#include #include #include #include #include using namespace std; int get_hash(int num) { int hash = 0; while (num > 0) { hash += num % 10; num /= 10; } if (hash >= 10) { return get_hash(hash); } return hash; } int main() { int k, n; cin >> k >> n; vector prime_check(n + 1, true); vector< pair > primes; prime_check[0] = prime_check[1] = false; for (int i = 4; i <=n; i += 2) { prime_check[i] = false; } for (int i = 3; i * i <= n; i += 2) { if (prime_check[i]) { for (int j = i + i; j <= n; j += i) { prime_check[j] = false; } } } for (int i = k; i <= n; i++) { if (prime_check[i]) { primes.push_back(make_pair(i, get_hash(i))); } } int max_len = 0; int ans = 0; for (int i = 0; i < primes.size(); i++) { int bits = 0; int len = 0; for (int j = 0; j < 10 && i + j < primes.size(); j++) { if ((bits & (1 << primes[i + j].second)) == 0) { bits |= 1 << primes[i + j].second; len++; } else { break; } } // printf("%d %d\n", primes[i].first, len); if (max_len <= len) { max_len = len; ans = primes[i].first; } } cout << ans << endl; return 0; }