#include"bits/stdc++.h" //#include using namespace std; #define print(x) cout<a; int cnt[10] = {}; int MAX = 5000000; bool dp[5000000]; bool hantei() { REP(i, 10) { if (a.count(i) == 0) { if (cnt[i] != 0)return false; } } return true; } bool ok() { REP(i, 10) { if (a.count(i) != 0) { if (cnt[i] == 0)return false; } } return true; } vector prime() { vector ret; for (int i = 2; i < MAX; i++) { if (dp[i]) continue; ret.push_back(i); for (int j = i + i; j < MAX; j += i) { dp[j] = true; } } return ret; } int main() { cin >> n; REP(i, n) { int t; cin >> t; a.insert(t); } vectorv = prime(); REP(i, 10)cnt[i] = 0; int ans = -1; int l = 1; REP(i, v.size()) { string tm = to_string(v[i]); REP(j, tm.size()) { cnt[tm[j] - '0']++; } if (!hantei()) { REP(j, 10)cnt[j] = 0; l = v[i] + 1; } if (ok()) { ans = max(ans, v[i+1]-1 - l); } if (a.size() == 10)ans = 4999999; } print(ans); return 0; }