#include<bits/stdc++.h>
#define LimValue 1000000000
using namespace std;
long long n,p,res;
bool is_min;
int main(){
cin>>n>>p;
if(n*p>LimValue){
cout<<0;
return 0;
}for(int i=0;i<n;i++){
res+=p;
if(res>LimValue){
cout<<0;
return 0;
}
for(int j=2;j<p;j++){
if(res%j==0){
i--;
break;
}
}
}cout<<res;
return 0;
}
求大佬指导