#include using namespace std; int get_hash( int v ){ if( v < 10 ) return v; int u = 0; while( v ) u += v % 10, v /= 10; return get_hash( u ); } signed main(){ int L, R; cin >> L >> R; vector< int > cnt( 10 ); deque< int > dq; int maxlen = 0, ans = -1; for( int i = R; i >= L; --i ){ int ng = 0; for( int j = 2; j * j <= i; ++j ) ng |= i % j == 0; if( ng ) continue; int hv = get_hash( i ); while( cnt[ hv ] ) --cnt[ dq.back() ], dq.pop_back(); ++cnt[ hv ], dq.emplace_front( hv ); if( maxlen < dq.size() ) maxlen = dq.size(), ans = i; } cout << ans << endl; return 0; }