#include #define REP(i,n) for(int i=0; i<(int)(n); i++) #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int f(int a){ int ret = 0; while(a){ ret |= 1 << (a % 10); a /= 10; } return ret; } int main(){ const int n = getInt(); int a = 0; REP(i,n) a |= 1 << getInt(); vector isPrime(5000000 + 1, true); int low = 1; int cur = 0; int ans = -1; for(int i = 2; i <= 5000000; i++){ if(isPrime[i]){ cur |= f(i); if(cur & ~a){ cur = 0; low = i + 1; } for(int j = i + i; j <= 5000000; j += i){ isPrime[j] = false; } } if(cur == a){ ans = max(ans, i - low); } } printf("%d\n", ans); return 0; }