/*
 * main.cpp
 *  use:to find how many apples there at the beginning if the monkeys divide the apple like this
 *  Created on: 2012-11-23
 *      Author: 12023
 */

int i=0,m=0,k=0;                                        //????????
int amnt(int a)                                          //??????????????????????? 
{
	if (a%(m-1)==0&&i<m)                               //????????????%m-1=0??????????????????????
	{
		i++;
		return amnt(a/(m-1)*m+k);

	}
	else if (i==m)                                      //???????????????????????
	{
		return a;
	}
	else                                             //???????0
		return 0;


}


int main()                                       
 {
	int n=0,j=1,b=0;                               //???????b??????????????
	cin>>m>>k;
    while (b!=1)                                   //??????????????
    {
        n=amnt(j);
	    if (n!=0)
	    {
	    	cout<<n;
	    	b=1;
	    }
	    j++;
	    i=0;                                       //?i?????0????????????
    }
    return 0;


}