#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

#define LIMIT 7400000
int prime[LIMIT+10];
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}
int*p;
int pcnt;

int main(){
	makep(LIMIT);
	rep(i,2,LIMIT)if(!prime[i])prime[pcnt++]=i;
	
	ll m,n;
	while(scanf("%lld%lld",&m,&n),m){
		p=calloc(m*m+10,sizeof(int));
		int flag=1;
		rep(i,m,m*m+1)if(!p[i]){
			if(!n--){
				printf("%lld\n",i);
				flag=0;
				break;
			}else{
				for(int j=i+i;j<=m*m;j+=i)p[j]=1;
			}
		}
		free(p);
		if(flag){
			rep(i,0,pcnt){
				if(prime[i]>m*m)if(!n--){
					printf("%lld\n",prime[i]);
					break;
				}
			}
		}
	}
}
