#include #define REP(i, x, n) for(int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F first #define S second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; const int MAX = 5000000; bool isPrime[MAX + 1]; void sieve(int N){ for(int i = 0; i <= N; i++) { isPrime[i] = true; } isPrime[0] = isPrime[1] = false; for(int i = 2; i <= N; i++) { if(!isPrime[i]) continue; for(int j = i + i; j <= N; j += i) { isPrime[j] = false; } } } int func(int v) { int res = 0; while(v) { int tmp = v % 10; v /= 10; res |= (1 << tmp); } return res; } int main() { // ios_base::sync_with_stdio(false); sieve(MAX); int N; cin >> N; int ok = 0; rep(i, N) { int A; cin >> A; ok |= (1 << A); } int ng = ((1 << 10) - 1) ^ ok; int ans = -1; int K = -1; int flg = 0; for(int i = 1; i <= MAX; i++) { if(K == -1) K = i; if(isPrime[i]) flg |= func(i); if(flg & ng) { K = -1; flg = 0; } else if(flg == ok) { ans = max(ans, i - K); } } cout << ans << endl; return 0; }