import java.io.PrintStream; import java.util.Scanner; public class Y443 { Scanner in = new Scanner(System.in); PrintStream out = new PrintStream(System.out); Y443() throws Exception { String s = in.next(); boolean[] flag = new boolean[10]; if (isRepetitive(s)) { out.println(s); return; } if (s.length() == 2) { int a = Integer.parseInt(s); int b = Integer.parseInt("" + s.charAt(1) + s.charAt(0)); out.println(gcd(a, b)); return; } if (s.length() == 3) { int a = Integer.parseInt(s); int b = Integer.parseInt("" + s.charAt(0) + s.charAt(2) + s.charAt(1)); int c = Integer.parseInt("" + s.charAt(1) + s.charAt(0) + s.charAt(2)); int d = Integer.parseInt("" + s.charAt(1) + s.charAt(2) + s.charAt(0)); int e = Integer.parseInt("" + s.charAt(2) + s.charAt(0) + s.charAt(1)); int f = Integer.parseInt("" + s.charAt(2) + s.charAt(1) + s.charAt(0)); long ans = gcd(a, gcd(b, gcd(c, gcd(d, gcd(e, f))))); out.println(ans); return; } int sum = 0; for (int i = 0; i < s.length(); i++) { sum += s.charAt(i) - '0'; } if (sum % 9 == 0) { flag[9] = true; } if (sum % 3 == 0) { flag[3] = true; } for (int i = 1; i < 10; i++) { if (i == 6) continue; if (allDigitsDivided(s, i)) { flag[i] = true; } } if (flag[4]) flag[2] = false; if (flag[8]) flag[4] = false; if (flag[9]) flag[3] = false; int ans = 1; for (int i = 0; i < 10; i++) { if (flag[i]) { ans *= i; } } out.println(ans); } boolean isRepetitive(String s) { for (int i = 0; i < s.length(); i++) { if (s.charAt(0) != s.charAt(i)) { return false; } } return true; } boolean allDigitsDivided(String s, int x) { for (int i = 0; i < s.length(); i++) { int y = s.charAt(i) - '0'; if (y % x > 0) { return false; } } return true; } long gcd(long x, long y) { while (y > 0) { x %= y; long t = x; x = y; y = t; } return x; } public static void main(String argv[]) throws Exception { new Y443(); } }