import java.util.HashSet;
public class t1252 {
public static void main(String[] args) {
int s=1;
int num=0;
while (s!=0){
int pow2 = num*num;
int pow3 = num*num*num;
HashSet<Object> set = new HashSet<>();
while (pow2!=0){
int n = pow2%10;
pow2= pow2/10;
set.add(n);
}
while (pow3!=0){
int n = pow3%10;
pow3= pow3/10;
set.add(n);
}
if (set.size()==10){
s=0;
}else {num++;}
}
System.out.println(num);
}
}