#include using namespace std; #define int long long #define ll long long typedef unsigned long long ull; ull modmul(ull a, ull b, ull M) { ll ret = a * b - M * ull(1.L / M * a * b); return ret + M * (ret < 0) - M * (ret >= (ll)M); } ull modpow(ull b, ull e, ull mod) { ull ans = 1; for (; e; b = modmul(b, b, mod), e /= 2) if (e & 1) ans = modmul(ans, b, mod); return ans; } bool isPrime(ull n) { if (n < 2 || n % 6 % 4 != 1) return (n | 1) == 3; ull A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}, s = __builtin_ctzll(n - 1), d = n >> s; for (ull a : A) { ull p = modpow(a%n, d, n), i = s; while (p != 1 && p != n - 1 && a % n && i--) p = modmul(p, p, n); if (p != n-1 && i != s) return 0; } return 1; } int ans = 0; void rec(int n, int cnt) { if (n == 0) return; // cout << n << " " << cnt << " << " << isPrime(n) << endl; if (!isPrime(n)) return; ans = max(ans, cnt); int inc = 0; int ml = 1; while (n > 0) { int lst = n % 10; n /= 10; rec(n*ml + inc, cnt + 1); inc += (lst*ml); ml *= 10; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; rec(n, 1); cout << ans << '\n'; return 0; }