/** * @FileName a.cpp * @Author kanpurin * @Created 2020.05.20 23:18:04 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n; cin >> n; int s = 0; vector< bool > a(10, false); for (int i = 0; i < n; i++) { int k; cin >> k; s |= (1 << k); a[k] = true; } const int N = 5000000; // エラトステネスの篩 O(NloglogN) // N以下の素数 vector< bool > isprime(N + 1, true); isprime[0] = isprime[1] = false; for (int i = 2; i * i <= N; i++) { if (isprime[i]) { for (int j = i + i; j <= N; j += i) { isprime[j] = false; } } } int ans = -1; int l = 1, r = 1; int m = 0; for (int i = 2; i <= N; i++) { if (i == N && m == s) { if (ans < N - l) { //cout << l << "->" << i << endl; ans = N - l; } // ans = max(ans, N - l); break; } if (isprime[i]) { int k = i; r = i; bool ok = true; int t = 0; while (k) { if (!a[k % 10]) { ok = false; } t |= (1 << (k % 10)); k /= 10; } if (!ok) { if (m == s) { if (ans < r - l - 1) { //cout << l << "->" << r - 1 << endl; ans = r - l - 1; } // ans = max(ans, r - l - 1); } l = i + 1; m = 0; } else { m |= t; } } } cout << ans << endl; return 0; }