#include using namespace std; using vi = vector; using ull = unsigned long long; using ll = long long; 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 false; } return true; } ll next (string str){ if(!str.size()) return 0; ll res = 0; ull n =stoull(str); if(isPrime(n)){ str = to_string(n); res++; ll maxn = 0; for(ll i = 0 ; i < str.size(); i++){ string tmp = str; maxn = max(next(tmp.erase(i, 1)), maxn); } res += maxn; } else { return 0; } return res; } void solve(){ ll num; cin >> num; cout << next( to_string(num)); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int t = 1; //cin >> t; while (t--){ solve(); } return 0; }