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(); int[] count = new int[10]; boolean[] flag = new boolean[10]; for (int i = 0; i < s.length(); i++) { count[s.charAt(i) - '0']++; } if (isRepetitive(s)) { out.println(s); return; } for (int i = 1; i < count.length; i++) { if (count[i] + count[0] == s.length()) { flag[i] = true; } } 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 (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; } public static void main(String argv[]) throws Exception { new Y443(); } }