#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool b[200020] = { false }; vector vec; int main() { int l, r; cin >> l >> r; b[1] = true; for (int i = 2; i <= 200000; i++) { if (!b[i]) { for (int j = i + i; j <= 200000; j += i) { b[j] = true; } } } for (int i = l; i <= r; i++) { if (!b[i]) { vec.emplace_back(i); } } int n = vec.size(); int ans = 0, ans1; set st; int right = 0; for (int left = 0; left < n; left++) { while (right < n) { auto itr = st.find(vec[right] % 9); if (itr != st.end() && st.size() != 0) { break; } st.insert(vec[right] % 9); right++; } if (ans <= right - left - 1) { ans = right - left - 1; ans1 = left; } if (right == left) { right++; } else { st.erase(vec[left] % 9); } } cout << vec[ans1] << endl; }