#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class Sieve { std::vector prime_; public: Sieve(int max) { prime_.resize(max, true); prime_[0] = prime_[1] = false; for(int i=2; i= 10) { s += h(n % 10); n /= 10; } s += n; return s>=10?h(s):s; } int main() { Sieve s(200000); int K, N; cin >> K >> N; std::vector S; std::vector Sh; for(int i=0;i seq; for(int i=0; i= max_length) { max_first = first; max_length = length; } length = i - seq[Sh[i]]; first = S[seq[Sh[i]]+1]; for(auto it=seq.begin();it!=seq.end();) { if(it->second < seq[Sh[i]]) { it = seq.erase(it); continue; } ++it; } seq[Sh[i]] = i; } } if(length >= max_length) { max_first = first; } cout << max_first << endl; }