void change(int n,int m,int *p)
{
	int i,j,q;
	for(i=0;i<m;i++)
	{
		q=*(p+n-1);
		for(j=n-1;j>0;j--) *(p+j)=*(p+j-1);
		*p=q;
	}
}
void main()
{
	int n,m,*p,i,q=0;
	scanf("%d%d",&n,&m);
	p=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++) scanf("%d",p+i);
	change(n,m,p);
	for(i=0;i<n-1;i++) printf("%d ",*(p+i));
	printf("%d\n",*(p+i));
}


int main()
{
    int *dt;
	int n,m;
	int j,i;
	scanf("%d%d",&n,&m);
	dt=(int *)malloc(sizeof(int)*n);
	for(i=0;i<(n-m);i++)
	{*(dt+i+m)=0;
		scanf("%d",&j);
	*(dt+i+m)=j;}
	for(i=(n-m);i<n;i++)
	{*(dt+i-n+m)=0;
		scanf("%d",&j);
	*(dt+i-n+m)=j;}
	printf("%d",dt[0]);
	for(i=1;i<n;i++)
	{printf(" %d",dt[i]);}
    free(dt);

	return 0;
}


void move(int *pstart,int n,int m)
{
	int lastnum;
	int *pmove;
	void (*pinfunction)(int *,int,int);           //actually,it seems that it's useless.....
	pinfunction=move;
	if (m>0)
	{
		lastnum=*(pstart+n-1);
		for (pmove=pstart+n-2;pmove>=pstart;pmove--) *(pmove+1)=*pmove;
		*pstart=lastnum;
		(*pinfunction)(pstart,n,m-1);
	}
}
void main()
{
	int flag,i,n,m;
	int num[100];
	int *pnum;
	void (*pinfunction)(int *,int,int);					//actually,it seems that it's useless.....
	pnum=num;
	scanf("%d",&n);
	scanf("%d",&m);
	for (i=0;i<=n-1;i++) scanf("%d",pnum++);
	pnum=num;
	pinfunction=move;
	(*pinfunction)(pnum,n,m);
	flag=0;
	for (i=0;i<=n-1;i++)
	{
		if (flag) printf(" ");
		else flag=1;
		printf("%d",*pnum++);
	}
}


int main()
{
	void order(int p,int q,int r[]);
	int n1,n2,i;
	int a[10000];
	scanf("%d %d",&n1,&n2);
	for(i=1;i<=n1;i++)
		scanf("%d",&a[i]);
	order(n1,n2,a);
	return 0;
}
void order(int n1,int n2,int a[])
{
	int i;
	for(i=n1-n2+1;i<=n1;i++)
		printf("%d ",a[i]);
	printf("%d",a[1]);
	for(i=2;i<=n1-n2;i++)
		printf(" %d",a[i]);
}


void move(int a[101], int n, int m)
{
    int *p, end;
    end=*(a+n-1);
    for(p=a+n-1; p>a; p--)
    *p=*(p-1);
    *a=end;
    m--;
    if(m>0)
    move(a, n, m);
}

int main()
{
    int a[101];
    int i, first=1;
    int n, m;
        scanf("%d%d", &n, &m);
    for(i=0; i<n; i++)
        scanf("%d", &a[i]);
    move(a, n, m);
    for(i=0; i<n; i++)
	{
		if(first)
			first=0;
		else printf(" ");
		printf("%d", a[i]);
	}
    printf("\n");
    return 0;
}


int t=0;
void range(int n,int m,int *p)
{
	if(t==m)
		return;
	else
	{
		t++;
		range(n,m,p);
		int v=*(p+n-1);
		int i;
		for(i=n-1;i>0;i--)
			*(p+i)=*(p+i-1);
		*p=v;

	}
}

void main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int num[100];
	int *p=num;
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	range(n,m,p);
	for(i=0;i<n-1;i++)
		printf("%d ",num[i]);
	printf("%d",num[n-1]);
}


int main()
{
	int n,m,i,j,a[100];
	int * shu;
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>a[i];
    shu=a+n-m;
	i=0;
	do{
		cout<<*shu<<" ";
		shu++;
		i++;
		if(shu>a+n-1) shu=a;

	}while(i<n-1);
	cout<<*shu;
	return 0;
}


int n,m,a[101];
void toscan()
{
  int i;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
}

void yidong(int n,int m,int a[])
{
  int t,i,j;
  for(i=0;i<m;i++)
   { for(j=n;j>0;j--)
        a[j]=a[j-1];
     a[0]=a[n];
   }
}

void toprint()
{ int i;
  printf("%d",a[0]);
  for(i=1;i<n;i++)
    printf(" %d",a[i]);
}
main()
{
  toscan();
  yidong(n,m,a);
  toprint();
  return 0;
}


void main()
{
    int n,m,i;
    int *p;
    int a[100];
    void change(int *p,int n,int m);
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    p=&a[0];
    change(p,n,m);
    printf("%d",*p);
    for(i=1;i<n;i++)
    printf(" %d",*(p+i));
    putchar('\n');
}
void change(int *p,int n,int m)
{
    int i;
    for(i=n-1;i>=0;i--)
    *(p+i+m)=*(p+i);
    for(i=0;i<m;i++)
    *(p+i)=*(p+i+n);
}


int main(){
	int N,m,temp;
	cin>>N>>m;
	const int n=N;
	int a[n];
	int *p=a;
	for(int i=0;i<=n-1;++i)
		cin>>*(p+i);
	for(int k=1;k<=m;++k){
		temp=*(p+n-1);
		for(int i=n-2;i>=0;--i)
			*(p+i+1)=*(p+i);
		*p=temp;
	}
	for(int i=0;i<=n-1;++i){
		if(i!=n-1) cout<<*(p+i)<<' ';
		else cout<<*(p+i);
	}
	return 0;
}


void main()
{
  void move(int array[],int x,int y);
  int num[120];
  int i,m,n;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)
  {
    if(i==n-1)
    scanf("%d",&num[i]);
    else scanf("%d ",&num[i]);
   }
   move(num,n,m);
   for(i=0;i<n;i++)
   {
     if(i==n-1)
     printf("%d",num[i]);
     else printf("%d ",num[i]);
    }
    printf("\n");
}
 void move(int array[],int x,int y)
{
  int *p,array_end;
  array_end=*(array+x-1);
  for(p=array+x-1;p>array;p--)
  *p=*(p-1);
  *array=array_end;
  y--;
  if(y>0)
  move(array,x,y);
}


int main(){
    int n,m,i;
    int s[100];
    scanf("%d %d",&n,&m);
    getchar();
    for(i=0;i<n;i++){
         scanf("%d",&(s[i]));
         getchar();
    }
    for(i=n-m;i<n;i++){
         printf("%d ",s[i]);
         getchar();
    }
    for(i=0;i<n-m-1;i++){
         printf("%d ",s[i]);
         getchar();
    }
    i=n-m-1;
    printf("%d",s[i]);
    return 0;
}


int main(int argc, char* argv[])
{
	int n,m,i,j;
	scanf("%d%d",&n,&m);

	int *x;
	x=(int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",x+i);
	}
	if(m==0){
		for(i=0;i<n;i++){
			if(i==n-1){
			printf("%d",*(x+i));
			break;
			}
		printf("%d ",*(x+i));
		}
		return 0;
	}
	int atmp;
	for(j=1;j<=m;j++){
		int tmp=(*(x));
		for(i=0;i<n-1;i++){
			atmp=(*(x+i+1));
			*(x+i+1)=tmp;
			tmp=atmp;
		}
		*x=tmp;
	}
	for(i=0;i<n;i++){
		if(i==n-1){
			printf("%d",*(x+i));
			break;
		}
		printf("%d ",*(x+i));
	}

	free(x);
	return 0;
}


void last_to_first (int *point,int lenth_of_n);

void main ()
{
	int num[100];
	int n,m;
	int i;
	int *point=num;

	scanf("%d %d",&n,&m);

	for(i=0;i<n;i++)
	{
		scanf("%d",point);
		point++;
	}

	for(i=0;i<m;i++)
	{
		last_to_first (num,n);
	}

	point=num;
	for(i=0;i<n;i++)
	{
		if(i!=0) printf(" ");
		printf("%d",*point);
		point++;

	}

}

void last_to_first (int *point,int lenth_of_n)
{
	int last;
	int i;
	point=(point+lenth_of_n-1);
	last=*point;

	for (i=1;i<lenth_of_n;i++)
	{
		*(point)=*(point-1);
		point=point-1;
	}

	*point=last;
}


void order(int m,int n)
{  int i,s[100];
  for(i=0;i<m;i++)
  scanf("%d",&s[i]);
  for(i=m-n;i<m;i++)
  printf("%d ",s[i]);
  for(i=0;i<m-n-1;i++)
  printf("%d ",s[i]);
  printf("%d",s[i]);
}
main()
{ int a,b;
  scanf("%d %d",&a,&b);
  order(a,b);
}


struct n
{
	int pi;
	struct n * next;
}num[100];
void main()
{
	int a[100],i,n,m;
	struct n *p;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		num[i].pi=a[i];
	}
	for(i=0;i<n-1;i++)
	{
		num[i].next=&num[i+1];
	}
	num[n-1].next=&num[0];
	p=&num[n-m];
	for(i=0;i<n-1;i++)
	{
		printf("%d ",p->pi);
		p=p->next;
	}
	printf("%d\n",p->pi);
}


void diaohuan(int *a,int m,int n);
main()
{
	int m,n,i,a[10000];
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	diaohuan(a,m,n);
	printf("%d",a[0]);
         for(i=1;i<n;i++) printf(" %d",a[i]);
}
void diaohuan(int *a,int m,int n)
{
	int *i;
	for(i=a;i<a+n-m;i++) *(i+n)=*i;
	for(i=a;i<a+n;i++) *i=*(i+n-m);
}


int m=0;
int main()
{
	int * change(int x[100],int y,int z);
	int a[100];
	int n,m,i;
	int *pt;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	pt=change(a,n,m);
	printf("%d",*pt);
	for(i=1;i<n;i++)
	{
		printf(" %d", *(pt+i));
	}
}
int * change(int x[100],int y,int z)
{
	int j,k,temp=0;
	for(j=0;j<z;j++)
	{
		temp=x[y-1];
		for(k=y-2;k>=0;k=k-1)
		{
			x[k+1]=x[k];
		}
		x[0]=temp;
	}
	return(x);
}


int main()
{
	int n,m,i;
	scanf("%d%d",&n,&m);

	int * p,* h;
	p=(int *)malloc(sizeof(int)*n);
	h=p;
	for(i=0;i<n;i++)
	{
		scanf("%d",p);
		p++;
	}
	p=h;
	for(i=n-m;i<n;i++)
	{
		printf("%d ",*(p+i));
	}
	for(i=0;i<n-m-1;i++)
		printf("%d ",*(p+i));
	printf("%d",*(p+n-m-1));
	free(p);
	return 0;
}


void main(){

    int a[MAX];

	int n,m,i,temp;

	int flag,istart,iend,length;

        	scanf("%d%d",&n,&m);
	//????
	for(i=0;i<n;i++)
		 scanf("%d",&a[i]);

	temp=n-m;
	if(n-m>m)
	{
		flag=0;/*<------*/
		length=m;
		istart=0;
		iend=n-1;
	}
	else
	{
		flag=1; /*----->*/
		length =n-m;
		istart=0;
		iend=n-1;
	}

	while (length>1) {

         /*
		 ??a[temp....temp+
		 swap(a,startpos,length);
		 */
		if( flag==0 )
		{
			 i=iend-length-length+1;
			 for(;i<iend-length+1;i++)
			 {
			   //???2*length

			   temp=a[i];
			   a[i]=a[i+length];
			   a[i+length]=temp;

			 }
			 iend=iend-length;

			 /*??????????*/

			 if(iend-length+1<= istart+length-1)

			 {
				 flag=1;
				 length=iend-length+1-istart;
			 }

		} else {/**flag==1**/

             i=istart;
			 for(;i<istart+length;i++)
			 {
			   //???2*length

			   temp=a[i];
			   a[i]=a[i+length];
			   a[i+length]=temp;

			 }
			 istart=istart+length;

			 /*??????????*/
			 if(iend-length+1<= istart+length -1)

			 {
				 flag=0;
				 length=iend-length+1-istart;
			 }

		}

	} //end while

 	if(length==1)

	{

		if(flag==0){
              temp=a[iend];
			  for(i=iend;i>istart;i--)
			  {
                a[i]=a[i-1];
			  }
			  a[istart]=temp;

		} else {
               temp=a[istart];
			  for(i=istart;i<iend;i++)
			  {
                a[i]=a[i+1];
			  }
			  a[iend]=temp;

		}

	}

	for(i=0;i<n-1;i++)
		 printf("%d ",a[i]);

	printf("%d",a[i]);

}


void yidong(int a1[],int len)
{
	int j,temp;
	for(j=1;j<len;j++)
	{
		temp=a1[j];
		a1[j]=a1[0];
		a1[0]=temp;

	}

	return;
}
int main()
{
	int n,m,i;
	int a[1000];
	scanf("%d %d",&n,&m);
	scanf("%d",&a[0]);
	for(i=1;i<n;i++)
	{
		scanf(" %d",&a[i]);
	}
	for(i=0;i<m;i++)
	{
		yidong(a,n);
	}
	printf("%d",a[0]);
	for(i=1;i<n;i++)
		printf(" %d",a[i]);
	return 0;
}


int main()
{
	int m,N,i;
	int *s;
	scanf("%d%d",&N,&m);

	s=(int*)malloc(sizeof(int)*N);
	for(i=m;i<N;i++){
		scanf("%d",&s[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d",&s[i]);
	}
	for(i=0;i<N;i++){
if(i<N-1){printf("%d ",s[i]);}
else{printf("%d",s[i]);}
	}
	return 0;
}


void main()
{
	void f(int *p,int n,int m);
	int n,m,num[100],i;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
    f(num,n,m);
	for(i=0;i<n;i++)
	{
		if(i==0)
			printf("%d",num[i]);
		else
			printf(" %d",num[i]);
	}
	printf("\n");
}
void f(int *p,int n,int m)
{
	int *q,b;
	q=p;
	b=*(p+n-1);
	for(q=p+n-1;q>p;q--)
		*q=*(q-1);
	*q=b;
	m--;
	if(m>0)
		f(p,n,m);

}


void main()
{
	int i,n,m,*p;
	scanf("%d%d",&n,&m);
	p=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
		scanf("%d",p+i);
	for(i=n-m;i<n;i++)
		printf("%d ",*(p+i));
	for(i=0;i<n-m-1;i++)
		printf("%d ",*(p+i));
	printf("%d\n",*(p+i));
}


void f(int a[],int n,int m,int i)
{
	if(i==n)
		return;
	int c,j;
	if(i<m)
		j=n-m+i;
	else
		j=i-m;
	c=a[j];
	f(a,n,m,i+1);
	a[i]=c;
	return;
}
void main()
{
	int a[100],n,m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	f(a,n,m,0);
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d",a[i]);
}


int *p=NULL;
void rearrange(int str[100],int n)
{
	int t;
	t=str[n-1];
	for(p=&str[n-2];p>=&str[0];p--)
	{
		*(p+1)=*p;
	}
	str[0]=t;
}
int main()
{

	int number[100];
	int n,m;
	cin>>n>>m;
	int i;
	for(i=0;i<n;i++)
		cin>>number[i];
	while(m--)
	{
		rearrange(number,n);
	}
	for(i=0;i<n-1;i++)
		cout<<number[i]<<" ";
	cout<<number[n-1];
    return 0;
}


struct node
{
	int num;
	struct node *next;
};

void main()
{
	int m,n,i,t;
	struct node *head=NULL, *p, *last=NULL;
	scanf("%d%d",&n,&m);
	head=(struct node*)malloc(sizeof(struct node));
	scanf("%d",&head->num);
	head->next=head;
	last=head;
	for(i=1;i<n;i++)
	{
		scanf("%d",&t);
		p=(struct node*)malloc(sizeof(struct node));
		p->num=t;
		last->next=p;
		p->next=head;
		last=p;
	}
	for(i=0;i<n-m%n;i++)
		head=head->next;
	printf("%d",head->num);
	for(i=1;i<n;i++)
	{
		head=head->next;
		printf(" %d",head->num);
	}
}


int main()
{
  int n,m,i,*num;
  scanf("%d%d",&n,&m);
  num=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
  {
  scanf("%d",num+i);
  }
   printf("%d",*(num+n-m));
  for(i=n-m+1;i<n;i++)
  {
    printf(" %d",*(num+i));
  }
  for(i=0;i<n-m;i++)
  {
   printf(" %d",*(num+i));
  }
  free(num);

	return 0;
}


struct element
{
  int num;
  struct element *next;
};
void main()
{
  int n,m,i;
  struct element *head,*p1,*p2,*p;
  scanf("%d%d",&n,&m);
  head=NULL;
  for(i=1;i<=n;i++)
  {
	p1=(struct element *)malloc(LEN);
    scanf("%d",&p1->num);
	if(i==1) head=p1;
	else p2->next=p1;
	p2=p1;
	if(i==n-m+1) p=p1;
  }
  p2->next=head;

  printf("%d",p->num);
  for(i=1;i<n;i++)
  {
    p=p->next;
	printf(" %d",p->num);
  }
}


void main()
{
	void move(int number[20],int n,int m);
	int number[20],n,m,i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&number[i]);
	}
	move(number,n,m);
	for(i=0;i<n-1;i++)
	{
		printf("%d ",number[i]);
	}printf("%d",number[n-1]);
}
void move(int a[20],int n,int m)
{
	int *p,end;
	end=*(a+n-1);
	for(p=a+n-1;p>a;p--)
    {*p=*(p-1);}
	*a=end;
	m--;
	if(m>0)move(a,n,m);
}


/*
 * xunhuanyidong.cpp
 *
 *  Created on: 2010-12-8
 *      Author: Administrator
 */
void move(int*x,int n,int m){
	 int *tmp=NULL,k,j;
	 tmp=x+n;
	 for(k=0;k<m;k++){
		 *(tmp+k)=*(x+n-m+k);
	 }
	 for(j=n-m-1;j>=0;j--){
	 	    *(x+j+m)=*(x+j);
	 }
	 for(j=0;j<m;j++){
	     *(x+j)=*(tmp+j);
	 }
}
int main(){
	int m,n;
	cin>>n>>m;
	int num[n],i;
	for(i=0;i<n;i++)  cin>>num[i];
	int *p;
	p=&num[0];
	move(p,n,m);
	for(i=0;i<n-1;i++)  cout<<num[i]<<" ";
	cout<<num[n-1]<<endl;
	return 0;
}


int main(){
    struct shu{
        int z;
        struct shu*next;
	}*shu,*header;
    int n,m,i,d=1;
    scanf("%d""%d",&n,&m);
    shu=(struct shu*)malloc(sizeof(struct shu)*n);
    for(i=0;i<n;i++){
        scanf("%d",&(shu[i].z));
	}
    header=&shu[n-m];
	for(i=n-m;i<n-1;i++){
		shu[i].next=&shu[i+1];
	}
	shu[n-1].next=&shu[0];
	for(i=0;i<n-m-1;i++){
		shu[i].next=&shu[i+1];
	}
	shu[n-m-1].next=NULL;
    struct shu*p;
    p=header;
    while(p!=NULL){
        printf("%d",p->z);
        p=p->next;
		if(d<n)printf(" ");
		d++;
	}
    free(shu);

    return 0;

}


int main()
{
	int n;
	scanf("%d",&n);
	int sz[300];
	for(int i=0;i<n;i++){
		scanf("%d",&sz[i]);
	}
	printf("%d",sz[0]);
	for(int j=1;j<n;j++){
        int k;
		for(k=0;k<j;k++){
			if(sz[j]==sz[k])
				break;
		}
		if(k==j){
			printf(",%d",sz[j]);
		}
		else
			continue;
	}
	return 0;
}


int main()
{
	int n,i,j,amount=0;
	static int a[300];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		do
		{
			scanf("%d",&a[i]);
		}
		while(a[i]==' ');
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<i;j++)
		{
			if (a[j]==a[i])
				goto no;
		}
		if(amount==0)
			printf("%d",a[i]);
		else
			printf(",%d",a[i]);
		amount=amount+1;

no:		continue;
	}
	return 0;
}


int main()
{
 int i,j,n,num[300],temp,flag=0;
 scanf("%d",&n);
 scanf("%d",&num[0]);
 for(i=1;i<n;i++)
 {
  scanf("%d",&temp);
  for(j=0;j<i;j++)
  {
   if(temp==num[j])
   {
    flag = 1;
    break;
   }
  }
  if(flag)
  {
   i--;
   n--;
  }
  else
  {
   num[i]=temp;
  }
  flag = 0;
 }
 for(i=0;i<n-1;i++)
 {
  printf("%d",num[i]);
   printf(",");
 }
 printf("%d",num[n-1]);
return 0;
}


int main(void)
{
	int n,MEDIA=0;scanf("%d",&n);
	int NUMO[n];int k=0;
	for(int i=0;i<=n;i++)
	{
		scanf("%d",&MEDIA);
		for(int j=0;j<k;j++)
		{
			if(NUMO[j]==MEDIA) goto SPEEEE;
		}
		NUMO[k]=MEDIA;
		k++;
		SPEEEE: ;
	}
	for(int i=0;i<k-1;i++)
	printf("%d,",NUMO[i]);
	printf("%d",NUMO[k-1]);
}


int g[300];

int main()
{
	int n;
	scanf("%d",&n);

	int k = 0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",g+k);
		for(int j=0;j<k;j++)
		{
			if(g[j]==g[k])
			{
				k--;
				break;
			}
		}
		k++;
	}

	printf("%d",g[0]);
	for(int j=1;j<k;j++)
		printf(",%d",g[j]);

	return 0;
}


char belong(int m,int a[],int j)
{
	int i;///belong dnt belong
	for(i=1;i<=j;i++)//
		if(m==a[i])
			return(0);
	return(1);
}

void main()
{
	int n,i,j=0,a[300],b[300]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		if(belong(a[i],b,j))
		{
			j++;
			b[j]=a[i];
		}
	for(i=1;i<=j-1;i++)
		printf("%d,",b[i]);
		printf("%d",b[j]);

}


void main()
{
	int n,i,j;
	int num[300];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	 scanf("%d",&num[i]);
	for(i=1;i<n;i++)
		for(j=0;j<i;j++)
			if(num[i]==num[j])
			{
				num[i]=0;
				break;
			}
	printf("%d",num[0]);
	for(i=1;i<n;i++)
		if (num[i]!=0)
			printf(",%d",num[i]);
}


void main()
{
	int n, input, output;
	int num[300];
	int i, j;
	scanf("%d", &n);
	scanf("%d", &num[0]);
	printf("%d", num[0]);
	for (i=1; i<n; i++)
	{
		scanf("%d", &num[i]);
		output=1;
		for (j=0; j<i; j++)
		{
			if (num[j]==num[i])
			{
				output=0;
			}
		}
		if (output==1)
		{
			printf(",%d",num[i]);
		}
	}
}


int main()
{
	int n , a[300] , shifouchuxian ;
	scanf("%d",&n);
	for(int i = 0;i<n;i++)
		scanf("%d",&a[i]);
	printf("%d",a[0]);
	for(int i = 1;i<n;i++)
	{
		shifouchuxian = 0;
		for(int j = 0;j<i;j++)
		{
			if(a[j] == a[i])                        				shifouchuxian += 1;                         		}
		if(shifouchuxian == 0)
			printf(",%d",a[i]);                       	}
	return 0;
}


int main(int argc, char* argv[])
{
	int a[300],n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[i]==-1)
				break;
			else if(a[i]==a[j])
				a[j]=-1;
		}
	}
	for(k=n-1;k>=0;k--)
	{
		if(a[k]==-1)
			continue;
		else
			break;
	}
	for(i=0;i<n;i++)
	{
		if(a[i]==-1)
			continue;
		else if(i==k)
		    printf("%d",a[i]);
		else
			printf("%d,",a[i]);
	}

	return 0;
}


int main(){
	int m=0,n=0,a=0,count=0,num=0;
	scanf("%d",&n);
	m=n;
	int *sz=(int *) malloc(sizeof(int) *n);
	for(int i=0;i<n;i++){
		scanf("%d",&sz[i]);
		for(int t=0;t<i;t++){
			if(sz[i]==sz[t]){
				a=1;
			}
		}
		if(a==1){
			sz[i]=0;
			m--;
		}
		a=0;
	}
	for(int k=0;k<n;k++){
		if(sz[k]!=0){
			printf("%d,",sz[k]);
			count++;
			num=k;
		}
		if(count==(m-1)){
			break;
		}
	}
	for(int j=num+1;j<n;j++){
		if(sz[j]!=0){
			printf("%d",sz[j]);
			break;
		}
	}
	return 0;
}


int main() {
	int n,num[500];
	cin>>n;
	int i,j;
	int temp;
	for (i=0;i<n;i++) cin>>num[i];
	for (i=0;i<n-1;i++) {
		temp=num[i];
		for (j=i+1;j<n;j++) {
			if (temp==num[j]) {
				num[j]=0;
			}
		}
	}
	for (i=0;num[i]==0;i++);
	if (i==n) return 0;
	cout<<num[i];
	for (++i;i<n;i++) {
		if (num[i]!=0) cout<<","<<num[i];
	}
	cout<<endl;
	return 0;
}


int count[10000];

int main()
{
	int i,j;
	int k;
	int num[1000];
	scanf("%d",&k);
	for(i=0; i<k; i++)
		scanf("%d", &num[i]);
	for(i=0; i<k; i++)
	{
		if(count[num[i]]==0)
		{
			count[num[i]]=1;
			printf("%d",num[i]);
			break;
		}
	}
	for(; i<k; i++)
	{
		if(count[num[i]]==0)
		{
			count[num[i]]=1;
			printf(",%d",num[i]);
		}
	}

	return 0;
}


int main()
{
    int n;
    cin >> n;

    int nums[n];

    for(int i = 0; i < n; i++)  cin >> nums[i];

    int *p,*end;
    p = nums;
    end = nums + n;
    while(true)
    {
        end=remove(p+1,end,*p);
        if(p!=end-1)
        {
            cout << *p << ',';
        }
        else
        {
            cout << *p;
            break;
        }
        p++;
    }
    return 0;
}


void main()
{
	int i,x=0,y,z=0,p,enter,count;
	int a[300];
	scanf("%d",&i);

	while(z<=i-1)
	{
		z++;
		count=0;
		scanf("%d",&enter);

		for(y=0;y<x;y++)
		{
			if(enter==a[y])
			count++;
		}
		if(count!=0) continue;
		a[x]=enter;
		x++;

	}

	for(p=0;p<x-1;p++)
	{
		printf("%d,",a[p]);
    }
	printf("%d",a[x-1]);

}


int main()
{
	int num[300],copy[300],sNum,i,count=0,j,flag=0;
	scanf("%d",&sNum);
	for (i=0;i<sNum; i++)
	{
		flag=0;
		scanf("%d", &num[i]);
		for (j=0;j<i;j++)
		{
			if (num[i]==copy[j])
			{
				flag=1;
				break;
			}
		}
        if (flag==0)
			{
				copy[count]=num[i];
				count++;
			}
	}

	for(j=0;j<count;j++)
	{
		printf("%d",copy[j]);
		if (j<count-1)
			printf(",");
	}
printf("\n");
return 0;
}


void main()
{
	int n;
	int flag=0;
	int i,j;
	struct number
	{
		int size;
		int mark;
	}num[300];
	scanf("%d",&n);

	for(i=0;i<n;i++)
		scanf("%d",&num[i].size);

	for(i=0;i<n;i++)
		num[i].mark=1;

	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(num[j].size==num[i].size)
				num[j].mark=0;
		}
	}

	for(i=0;i<n;i++)
	{

		if(num[i].mark==1)
		{
			if(flag==1)
				printf(",");
			flag=1;
			printf("%d",num[i].size);
		}
	}

printf("\n");
}


int main ()
{
	int judge=0,b[300],*c[300],num,i,k,j;scanf("%d",&num);
    for(i=0;i<num;i++)        {*(c+i)=&b[i];}

	for(i=0;i<num;i++)
	   scanf("%d",*(c+i));
	for(i=0;i<num;i++)
	{
        if(*(c+i)==NULL)   continue;
		k=**(c+i);
		for(j=i+1;j<num;j++)
		{if(*(c+j)==NULL)   continue;
		if(**(c+j)==k)  *(c+j)=NULL;}
	}
	for(i=0;i<num;i++)
	{
		if(*(c+i)==NULL)   continue;
        printf("%d",**(c+i));
		break;
	}
	for(i++;i<num;i++)
	{
		if(*(c+i)==NULL)   continue;
        printf(",%d",**(c+i));
	}

	return 0;
}


int main()
{
	int content[300];
	int i, n, m=0, j;
	int temp;
	short flag;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &temp);
		flag = 0;
		for (j=0; j<m; j++){
			if (content[j]==temp)
				flag = 1;
		}
		if (!flag)
			content[m++] = temp;
	}

	for(i=0; i<m; i++){
		printf("%d", content[i]);
		if (i<m-1)
			printf(",");
	}

	return 0;
}


int main()
{
	int i,j,k=1,n,result[300],tem[300];
	scanf("%d",&n);
	scanf("%d",&tem[0]);
	result[0]=tem[0];
	for (i=1;i<n;i++)
	{
		scanf("%d",&tem[i]);
		for(j=0;j<i;j++)
		{
			if(tem[i]==result[j])
				break;
			if(j==i-1)
			{
				result[k]=tem[i];
				k++;
			}
		}
	}
	for (i=0;i<k-1;i++)
	{
		printf("%d,",result[i]);
	}
	printf("%d",result[k-1]);
	return 0;
}


void main()
{
int a[300],b[300],i,j=0,n;
int eva(int x,int y,int b[]);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d ",&a[i]);
for(i=0;i<n;i++)
{
if(eva(a[i],j,b))    {b[j]=a[i];j=j+1;}
}
for(i=0;i<j-1;i++)
printf("%d,",b[i]);
printf("%d",b[j-1]);
}

int eva(int x,int y,int b[])
{int i;
for(i=0;i<y;i++)
if (x==b[i]) {return(0);break;}
 return(1);
}


int compare(int s, int a[100], int n)
{
	int i, temp=0;
	for(i=0; i<n; i++)
	{
		if(s==a[i])
		{
			return 1;
			temp=1;
			break;
		}
		else
			continue;
	}
	if(temp=0)
		return 0;
}

int main()
{
	int n, a[100], i, j, w=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d", &a[i]);
		if(compare(a[i], a, i)==1)
			a[i]=-1;
		else
			continue;
	}
	for(i=0; i<n; i++)
	{
		if(a[i]==-1)
			continue;
		else
		{
			if(w==0)
				printf("%d", a[i]);
			else
				printf(",%d", a[i]);
			w++;
		}
	}
	printf("\n");
	return 0;
}


int main()
{
	int num[100],str[100];
	int i,j,k,l,m,n,index=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	printf("%d",num[0]);
	for(i=1;i<n;i++)
	{
		index=0;
		for(j=0;j<i;j++)
		{
			if(num[i]==num[j])
				index++;
		}
		if(index==0)
			printf(",%d",num[i]);
	}
}


void main()
{
	int n,i;
	int a[301];
	int* input=a;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int temp;
		int isinsert=1;
		scanf("%d",&temp);
		int *find=a;
		while(find!=input)
		{
			if(temp==*(find))
			{
				isinsert=0;
				break;
			}
			find++;
		}
		if(isinsert==0)
			continue;
		*input=temp;
		input++;
	}
	int *begin=a;
	printf("%d",*begin);
	begin++;
	while(begin!=input)
	{
		printf(",%d",*begin);
		begin++;
	}
}


int main(){
    int n,number[300],i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
                     scanf("%d",&number[i]);
                     }
    for(i=0;i<n;i++){
                     for(j=i+1;j<n;j++){
                                        if(number[i]==number[j])
                                        number[j]=-3;
                                        }
                     }
    printf("%d",number[0]);
    for(i=1;i<n;i++){
                     if(number[i]>-1)
                     printf(",%d",number[i]);
                     }
    return 0;
}


int main()
{
 int i,j,n,num[300],temp,flag=0;
 scanf("%d",&n);
 scanf("%d",&num[0]);
 for(i=1;i<n;i++)
 {
  scanf("%d",&temp);
  for(j=0;j<i;j++)
  {
   if(temp==num[j])
   {
    flag = 1;
    break;
   }
  }
  if(flag)
  {
   i--;
   n--;
  }
  else
  {
   num[i]=temp;
  }
  flag = 0;
 }
printf("%d",num[0]);
 for(i=1;i<n;i++)
 {
  printf(",%d",num[i]);
 }
return 0;
}


int main(){
 int n;
 scanf("%d",&n);
 int shuzu[300],i,j;

 for(i=0;i<n;i++){
  scanf("%d",&shuzu[i]);
 }

    int zhuanhuan[300];
 zhuanhuan[0]=shuzu[0];
 printf("%d",zhuanhuan[0]);

 int a=1;
 int b;

 for(i=1;i<n;i++){
  b=0;
  for(j=0;j<a;j++){
   if(shuzu[i]==zhuanhuan[j]){
    break;
   }else{
                b++;

   }
   if(b==a){
    zhuanhuan[a]=shuzu[i];
    printf(",%d",shuzu[i]);
    a++;
   }
  }

 }

 return 0;
}


 typedef struct linknode
 {
       int inf;
	   struct linknode *next,*prev;
 } snode,*ptr;

 main ()
 {
     int i,j,l,k,n,syn;
	 ptr head,p1,p2,p3;

	 k=0;
	 scanf ("%d",&n);
     for (i=1;i<=n;i++)
	 {

		 scanf ("%d",&l);  syn=0;

		 if (i!=1)
		 {
		   p2=head;
		   for (j=1;j<=k;j++)
		   {
			   if (l==(*p2).inf ) {syn=1; }
			 if (j!=k) p2=((*p2).next ) ;
		   }
		 }

		 if (syn==0)
		 {
		    p1=(ptr)malloc(sizeof(snode));
			(*p1).inf =l;
		    if (k==0) {head=p1; p2=p1;}

	     	 else {(*p2).next =p1;}
            k++;
		 }

	 }

	 p1=head;

	 for (i=1;i<=k;i++)
	 {

		 printf ("%d",(*p1).inf  );
		 if (i!=k) {p1=(*p1).next ; printf (",");}

	 }
	 printf ("\n");

 }


int main()
{
	int n;
	cin>>n;
	int a[500];
	int t=1,s;
	int i,j,k,l;
	cin>>a[0];
	cout<<a[0];
	for(i=1;i<n;i++)
	{
		cin>>s;
		for(j=0;j<t;j++)
		{
			if(s==a[j]) break;
		}
		if(j==t) {cout<<","<<s;a[t]=s;t++;}
	}
	cout<<endl;
	return 0;
}


int test(int *,int *,int);
int main(){
	int n,integer[300],aux,*curp,i;
	scanf("%d%d",&n,integer);
	n--;
	for(curp=integer;n>0;n--){
		scanf("%d",&aux);
		if(test(integer,curp,aux)){
			curp++;
			*curp=aux;}}
	for(i=0;integer+i<curp;i++)
		printf("%d,",*(integer+i));
	printf("%d\n",*curp);
	return 0;}
int test(int *p1,int *p2,int aux){
	for(;p2>=p1;p2--){
		if(*p2==aux)	return 0;}
	return 1;}


int main(){
    int n,i,j;
    scanf("%d",&n);
    int sz[n];
    int ssz[n],count=0;
    for(i=0;i<n;i++){
        scanf("%d ",&sz[i]);
        }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(sz[j]==sz[i]){
                sz[j]=0;
                }
            }
        }
    for(i=0;i<n;i++){
        if(sz[i]!=0){
            ssz[count]=sz[i];
            count++;
        }
    }
    printf("%d",ssz[0]);
    for(i=1;i<count;i++){
        printf(",%d",ssz[i]);
        }
    return 0;
}


void main()
{
 int n,num[300],temp,flag=0,*p,*q;
 scanf("%d",&n);
 scanf("%d",&num[0]);
 for(p=num+1;p<(num+n);p++)
 {
  scanf("%d",&temp);
  for(q=num;q<p;q++)
  {
   if(temp==*q)
   {
    flag = 1;
    break;
   }
  }
  if(flag==1)
  {
   p--;
   n--;
  }
  else *p=temp;
  flag = 0;
 }
 printf("%d",*num);
 for(p=num+1;p<(num+n);p++)
     printf(",%d",*p);
}


void main()
{
	int n,*a,i,j,*p,t=0;
	scanf("%d",&n);
	a=(int*)malloc(n*sizeof(int));
	p=a;
    for(i=0;i<n;i++)
	{
		scanf("%d",p);
		for(j=0;j<i-t;j++)
			if(*p==a[j]) break;
			if(j!=i-t) {t++;continue;}
		p++;
	}
	p=a;
	for(i=0;i<n-t;i++)
	{
		printf("%d",*p++);
		if(i!=n-t-1) printf(",");
	}
}


int n;
struct num
{
	int shu;
	struct num *next;
};
struct num *creat()
{
	struct num *p1,*p2,*head;
	p2=p1=(struct num*)malloc(LEN);
	scanf("%d",&p1->shu);
	p1->next=NULL;
	head=p1;
	n=n-1;
	while(n)
	{
		p1=(struct num*)malloc(LEN);
		scanf("%d",&p1->shu);
		p1->next=NULL;
		p2->next=p1;
		p2=p1;
		n--;
	}
	return head;
}
void main()
{
	scanf("%d",&n);
	struct num *head,*p,*q,*qpre;
	head=creat();
	for(p=head;p!=NULL;p=p->next)
		for(q=p->next,qpre=p;q!=NULL;)
		{
			if(q->shu==p->shu)
			{
				qpre->next =q->next;
				q=qpre->next ;
			}
			else
			{
				qpre=q;
				q=q->next;
			}
		}
	printf("%d",head->shu);
    for(p=head->next;p!=NULL;p=p->next)
	    printf(",%d",p->shu);
}


int main()
{
 int array[300],n,i,j;
 int p,q;
 scanf("%d",&n);
 for (i=0;i<n;i++)
  scanf("%d",&array[i]);

 for (p=0;p<n-1;p++)
 {
  for (q=p+1;q<n;q++)
  {
   if (array[p]==array[q])
   {
    for (j=q;j<n-1;j++)
    {
     array[j]=array[j+1];
    }
    n--;q--;
   }
  }
 }
 printf("%d",array[0]);
 for (i=1;i<n;i++)
 {
  printf(",%d",array[i]);
 }
 return 0;
}


int main()
{
    int sz[400];
    int sub[400];
    int n,count=0,bar=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
            scanf("%d",&sz[i]);
    }
    for(int j=0;j<n;j++){
            for(int a=0;a<count;a++){
                    if(sz[j]==sub[a]){
                             bar=1;
                    }
            }
            if(bar==0){
                       if(j==0){
                                printf("%d",sz[j]);
                                sub[count]=sz[j];
                                count++;
                       }
                       else{
                                printf(",%d",sz[j]);
                                sub[count]=sz[j];
                                count++;
                       }
            }
            bar=0;
    }
	return 0;
}


int main()
{
       int n;
       scanf("%d",&n);
       int list1[300];
       int list2[300];
       int i,j,count=0;
       for(i=0;i<n;i++)
         scanf("%d",&list1[i]);

       for(i=0;i<n-1;i++)
		if(list1[i]==0)
			continue;
		else
		{
		     list2[count]=i;
		     count++;
		     for(j=i+1;j<n;j++)
		          if(list1[i]==list1[j])
			      list1[j]=0;
		}
       if(list1[n-1]!=0)
       {
                 list2[count]=n-1;
                 count++;
       }

       for(i=0;i<count-1;i++)
                  printf("%d,",list1[list2[i]]);
       printf("%d",list1[list2[count-1]]);
       return 0;
}


int main(){
int n;
cin>>n;
int shuzu[100];

for(int i=0;i<n;i++){
cin>>shuzu[i];
}
for(int k=0;k<n;k++){
	if (shuzu[k]==0) {continue;}
	for(int j=k+1;j<n;j++){
		if (shuzu[j]==shuzu[k]) {shuzu[j]=0;}
		}
}
int t;
for(int q=0;q<n;q++){
	if (shuzu[q]!=0) cout<<shuzu[q];t=q;break;}

for(int w=t+1;w<n;w++){
 if (shuzu[w]==0) continue;
 cout<<","<<shuzu[w];
}

//for(i=0;i<n;i++){cout<<shuzu[i];}

return 0;

}


int main()
{
	int a[300]={0},n,num,count=0,i,j;
	scanf("%d",&n);
	num=n;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[count]);
		for(j=0;j<count;j++)
		{
			if(a[j]==a[count])
			{
				num--;
				break;
			}
		}
		if(j==count)
		{
			count++;
		}
	}
	for(i=0;i<num-1;i++)
		printf("%d,",a[i]);
	printf("%d\n",a[num-1]);

	return 0;
}


void main()
{
	int a,i,j,no[N],judge[N]={0};
	scanf("%d",&a);
	getchar();
	for(i=0;i<a;i++)
	{
		scanf("%d",&no[i]);
	}
	for(i=0;i<a;i++)
		if(judge[i]==0)
			for(j=i+1;j<a;j++)
				if(no[j]==no[i])
					judge[j]=1;
	printf("%d",no[0]);
	for(i=1;i<a;i++)
		if(judge[i]==0)
			printf(",%d",no[i]);
	printf("\n");
}


int main()
{
    int n;
	scanf("%d ",&n);
	int sz[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&sz[i]);
	}
	for(int j=0;j<n;j++)
	{
		if(j==0)
		{
			printf("%d",sz[j]);
		}
		else
		{   int x=j;
			for(int k=0;k<j;k++)
			{
                if(sz[j]!=sz[k])
				{
                 x--;
				}
			}
				if(x==0)
				{
					printf(",%d",sz[j]);
				}

		}
	}
	return 0;
}


int main()
{
  int n,a[300],d[300],i=0,*p;
  int judge(int *w,int i,int *p);
  scanf("%d",&n);
  for(p=a;p<a+n;p++)
  {
  scanf("%d",p);
  }
  for(p=a;p<a+n;p++)
  {
  if(judge(d,i,p)==0)
  {d[i]=*p;i++;}
  }
  for(p=d;p<d+i;p++)
  {
	  if(p==d)printf("%d",*p);
	  else printf(",%d",*p);
  }

	  return 0;
}
int judge(int *w,int i,int *p)
{

	int *pi=w;
		for(;pi<w+i;pi++)
		{

			if(*p==*pi) return 1;
		}
return 0;
}


 int n,k,i;
int f(int x) {
 int t;
	if(x==n) 		 {
	t=n*i+k; 	 i++;	 	return t;
}
	 for(;;) {
t=f(x+1) ;
 if(t%(n-1)==0) 	 {
 t=t/(n-1)*n+k; 	 return t;
 }
}
}
 int main() {
 cin>>n>>k;
 	 cout<<f(1)<<endl;
 return 0;
}


int minm(int n,int k);
void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d\n",minm(n,k));
}
int minm(int n,int k)
{
	int i,j,m;
	m=n-1;
	for(j=1;;j++){
		m=j*(n-1);
		for(i=1;i<=n;i++){
			if(m%(n-1)!=0) break;
			m=m+m/(n-1)+k;
			if(i==n) return m;
		}
	}
}


//
//  main.cpp
//  relocateapples
//
//  Created by ? ?? on 13-11-21.
//  Copyright (c) 2013? LEE. All rights reserved.
//

int n,k;//??????????total??x??
int total=0;
float xishu=0.0;
int main()
{   int msees(int x,int y);
    cin>>n>>k;
    total=n;int i;
    xishu=(float)n/(n-1);//???????????????float??
while(true)
    {for(i=1;i<=n;i++)
        { if((msees(i,k)-k)%n!=0)//???????????
            break;
        }

    if(i==n+1)break;
    total+=n;
    }
        cout<<msees(n,k)<<endl;

    return 0;
}

int msees(int x,int y)
{
    if(x==1)return total+y;//??????????????????n+k???
    return y+xishu*msees(x-1,y);//??????
}


int n, k, r;

int main()
{
    int num(int, int);

    cin >> n >> k;
    r = k + n;
    while(num(n, r) == 0)
    {
        r = n + r;
    }
    cout << num(n, r) << endl;

    return 0;
}

int num(int a, int b)
{
    if(a == 1) return b;
    else
    {
        if(b % (n - 1) == 0)
        {
            b = b * n / (n - 1) + k;
            return num(a - 1, b);
        }

        else
        {
            return 0;
        }
    }
}


int main()
{
     int n,m,k;
     scanf("%d %d",&n,&k);
     if(n>2)
     {
        m=(int)pow(n,n)-(n-1)*k;
     }
     else
     {
        m=7;
     }
     printf("%d\n",m);
     return 0;
}


int main()
{
	int i,n,k;
    long s;
    cin>>n>>k;
    if(n==1) cout<<1;
    else if(n==2) cout<<7;
    else
	{
      s=n;
      for(i=1;i<n;i++) s*=n;
      s-=k*(n-1);
      cout<<s;
	}
    return 0;
}


int pingguo(int a,int b);
int main()
{
	int n,k,y;
	scanf("%d%d",&n,&k);
	y=pingguo(n,k);
	printf("%d",y);
	return 0;
}

int pingguo(int a,int b)
{
	int i,z,k=1,j;
	while(1)
	{
		j=1;
		z=k*a+b;
		for(i=1;i<a;i++)
		{
			if(z%(a-1)==0)
			{
				z=z/(a-1)*a+b;
				j=j+1;
			}
			else
			{
				k=k+1;
				break;
			}

		}
		if(j==a) break;
	}
	return z;
}


int main()
{
	int m=1,n,k,t;
	int devide(int m,int n,int k);
	scanf("%d%d",&n,&k);
	for(m=1;;m++)
	{
		t=devide(m,n,k);
		if(t==1)
		{
			printf("%d", m);
			break;
		}
	}
	getchar();
}
int devide(int m,int n,int k)
{
	int t, i;
	t=m;
	for(i=1;i<=n;i++)
	{
		if(t%n==k)
			t=t-t/n-k;
		else
			break;
	}
	if (i>n&&t>=1)
		return 1;
	else
		return 0;
}


int abc(int c,int d,int e)
{
	c=c*d/(d-1)+e;
	return c;
}
void Sum(int a,int b)
{
	int m=1,i=1,j=0;
	while (j != a)
		{
			m=i;
			for (j=0;j<a;j++)
				if (m%(a-1) == 0)
					m=abc(m,a,b);
				else
					{
						i++;
						break;
					}
		}
	cout << m << endl;
}

int main()
{
	int n,k;
	cin >> n >> k;
	Sum (n,k);
	return 0;
}


void main()
{
	int apple(int m,int n,int k);
	int m,n,k,i;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		m=i;
		m=apple(m,n,k);
		if(m!=0){printf("%d\n",m);break;}
	}
}
int apple(int m,int n,int k)
{
	int j;
	for(j=1;j<=n;j++)
	{
		if(m%(n-1)==0)m=m*n/(n-1)+k;
		else{m=0;break;}
	}
	return(m);
}


signed int function( int n , int k , int last );
int totalmember;
int lastnumber;
int main()
{
	int k,i=1;
	cin>>totalmember>>k;
	lastnumber=0;
	while( i )
	{
		lastnumber++;
		if( function( totalmember , k ,lastnumber ) != -k*(totalmember-1) )
		{
			cout<<function( totalmember , k , lastnumber )<<endl;
			i--;
		}
	}
}

signed int function( int n  , int k , int last )
{
	if( n==1 )
	{
		return( totalmember * last + k );
	}
	else
	{
		if( function ( n-1 , k , last ) % ( totalmember-1 ) == 0 )
		{
			return( totalmember * function( n-1 , k , last ) / ( totalmember-1) + k );
		}
		else
		{
			return( -k*( totalmember-1 ) );
		}
	}
}


void main()
{
	int n,k,m,i;
	scanf("%d %d",&n,&k);
    if(n!=2){m=pow(n,n)-(n-1)*k;
	printf("%d",m);}
	else printf("%d",7);
}


int apple(int n, int k)
{
    if(n==2)
        return 2*pow(n,n)-(n-1)*k;
    else
        return pow(n,n)-(n-1)*k;
}

int main()
{
    int n,k;

    scanf("%d %d", &n, &k);
    printf("%d\n", apple(n,k));

    return 0;
}


int n , k ;
int p = 1 ;
int monkey(int t)
{
	int x = 0;
	if(t == 1)
		return p*n +k ;
	else
	{
		while((monkey(t-1) % (n-1) != 0))
		{
			p++;
		}
			return (monkey(t-1)*n/(n-1)+k) ;
	}
}
int main ()
{
	cin >> n >> k ;
	cout << monkey(n) <<endl ;
	return 0 ;
}


fen(int n,int k)
{
	int m,i,t;
	for(m=1;;m++){
		for(i=0,t=m;i<n;i++){
			if(t%n==k)
				t-=t/n+k;
			else
				break;
		}
		if(i>=n&&t>=1)
			break;
	}
	return m;
}

main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	printf("%d\n",fen(n,k));
}


void main()
{
	int n,k;
	void apple(int x,int y);
	scanf("%d%d",&n,&k);
	apple(n,k);

}
void apple(int x,int y)
{
	int a=1,b,i=2,p=1;
	b=x+y;
	while(i<=x)
	{
		if(b%(x-1)==0)
		{
			a=b/(x-1);
			b=a*x+y;
		i=i+1;}
		else
		{
			p=p+1;

			a=p;
			b=a*x+y;
			i=2;

		}

	}
	printf("%d\n",b);
}


int key(int rest,int monkey,int count,int k)
{
	if(count==1)
        return (rest>k&&(rest-k)%monkey==0)?1:0;
	else
		return (rest>k&&(rest-k)%monkey==0)?key((rest-k)*(monkey-1)/monkey,monkey,count-1,k):0;
}
void main()
{
	int i,n,k;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
		if(key(i,n,n,k)==1)
		{
			printf("%d\n",i);
		    break;
		}
}


long int power(int a,int b)
{
	int i,pro=1;
	for (i=1;i<=b;i++)
    pro*=a;
	return pro;
}
main()
{
	int n,k;
	long int m,a,p,q;
	scanf("%d %d",&n,&k);
	p=power(n-1,n-1);
	q=power(n,n-1);
	a=p-k;
	while (a<=0)
		a+=p;
	m=n*((a+k)/p*q-k)+k;
	printf("%ld\n",m);
    return 0;
}


void main()
{
	int n,k,m,re;
	int f(int n,int k,int time,int m);
	scanf("%d%d",&n,&k);
	m=0;
	do
	{
		m++;
		re=f(n,k,n,m);
    }while(re<0);
	printf("%d\n",re);
}
int f(int n,int k,int time,int m)
{
	int z,a;
	if(time>1)
	{
		z=f(n,k,time-1,m);
		if(z==-1||z%(n-1)!=0) a=-1;
		else a=n*z/(n-1)+k;

	}
	else a=m*n+k;
	return(a);
}


int main()
{
	int monkey[1000],n,k,i=3;
	cin>>n>>k;
	monkey[n]=k;
	while(i>=1)//??i?????
	{
		monkey[n]+=n;
		for(i=n-1;i>=1;i--)
		{
			if(monkey[i+1]%(n-1)!=0)
				break;
			else
				monkey[i]=monkey[i+1]*n/(n-1)+k;
		}
	}
	cout<<monkey[1];
	return 0;
}


/*
 * 1000012712_324.cpp
 *
 *  Created on: 2010-11-21
 *      Author: Administrator
 */
int main(){
	int n,k,i;
	cin>>n>>k;
	int apple[n];
	apple[1]=n+k;
	while(true){
		for(i=2;i<=n;i++){
			apple[i]=(apple[i-1]-k)/n*(n-1);
			if((apple[i]%n!=k)||(apple[i]<n)) break;
	    }
		if(i==n+1)  break;
		else  apple[1]+=n;
	}
	cout<<apple[1]<<endl;
	return 0;
}


int n, k, m;
long long a[1000];

int vampire(int n, int k, int p)
{
    int i;
    a[n] = p * n + k;
    if(n == 1 || a[n] % (n - 1) == 0)
    {
        for(i = n - 1; i >= 1; i--)
        {
            a[i] = a[i + 1] * n / (n - 1) + k;
            if(i != 1 && a[i] % (n - 1) != 0)
                break;
        }
        if(i == 0)
            return a[1];
    }
    ++ p;
    while (n != 1 && (p * n + k) % (n - 1) != 0)
        ++ p;
        return vampire(n, k, p);

}
int main()
{
    cin >> n >> k;
    m = vampire(n, k, 1);
    cout << m << endl;
    return 0;
}


int n, k;
int apples;

int func(int monkeys) {
	if (monkeys == n)
		return apples++;

	int tmp = func(monkeys + 1);
	while (tmp % (n - 1) != 0)
		tmp = func(monkeys + 1);
	return k + tmp*n / (n - 1);
}

int main() {
	cin >> n >> k;
	apples = n - 1;
	cout << func(0) << endl;
}


int e;
int cs(int i,int n,int m)
{
if (e==0) return(1);
else
	{
	if (i%n==m&&i>n) {e--;return(cs(i/n*(n-1),n,m));}
	else return(0);
	}
}

void main()
{
int n,m,i;
scanf("%d %d",&n,&m);

for(i=1;;i++)
	{e=n;
	if (cs(i,n,m)==1) {printf("%d",i);break;}
	}
}


int main()
{
	int n, k, m,y=0,i,p;
	scanf("%d%d", &n, &k);
	for (m = 1; y != n; m++)
	{
		p = m; y = 0;
		for (i = 1; i <= n; i++)
		{
			if (i < n)
			{
				if (p%n == k)
				{
					p = p - p / n - p%n;
					y++;
				}
				else
					break;
			}
			else
			{
				if (p <= n)
					break;
				else if (p%n != k)
					break;
				else
					y++;
			}
		}
	}
	printf("%d", m - 1);
	return 0;
}


int allocable(int n,int m,int k)
{
if (m%n==k) return 1;
else
return 0;
}

void main()
{
int n,k,m;
int i;

scanf("%d %d",&n,&k);

m=1;
while(1)
{
m++;
int tmp=m;
for (i=0;i<n;i++)
{
if (allocable(n,tmp,k))
{
       tmp=(tmp-k)*(n-1)/n;
}
else
break;

}

if (i==n) break;

}

printf("%d",m);

}


int n=0,k=0;

int f(int depth,int a)
{
    if (depth==n) return a;
    if (a%(n-1)==0) return f(depth+1,a*n/(n-1)+k);
    return 0;
}

int main()
{
    int i=1,t=0;
    cin>>n>>k;
    while(true)
    {
        t=f(1,i*n+k);
        if(t!=0)break;
        else i++;
    }
    cout<<t;
    return 0;
}


int jisuan(int n,int k)
{
    const int boyNum=k;
    unsigned int m=1;
    unsigned int num;
    unsigned int allNum;//????
    int i=0;
    while(i<n-1)
    {
    num = m;
    for(;i<n-1;i++)
    {
    allNum = num*n+boyNum;
    if((allNum%(n-1)) != 0)
    {
     i=0;//??????
     break;

    }
    num = allNum/(n-1);//???(n-1)
    }
    m++;
    }
    allNum = num*n+boyNum;
    return(allNum);

}

main()
{
      int n,k;
      scanf("%d%d",&n,&k);
      unsigned int jisuanzhi;
      jisuanzhi=jisuan(n,k);
      printf("%u",jisuanzhi);
      getchar();getchar();

}


int main()
{
	int n,k,apple,m,i;
	cin>>n>>k;
	apple=k;
	do
	{
		apple+=n;
		m=apple;
		for(i=n-1;i>=1;i--)
			if(m%(n-1)==0)
				m=m*n/(n-1)+k;
			else
				break;
	}
	while(i>=1);
	cout<<m;
	return 0;
}


void main()
{
	int n,k;
	int t;
	double p;
	scanf("%d %d",&n,&k);
	if (n!=2)
	{
		p=pow((double)n,(double)n);
		t=(int)p-n*k+k;
	}
	else
		t=7;
	printf("%d",t);
}


int main()
{
	int n, i, k, sum;
	cin >> n >> k;
	if ((n == 2) && (k == 1))
	{
		cout << "7" << endl;
		return 0;
	}
	sum = 1;
	for (i = 1; i <= n; i++)
	{
		sum = sum * n;
	}
	cout << sum - k * (n - 1) << endl;
	return 0;
}


int judge_output(int n,int k, int j,int a1)
{
	int tp,out;
	if(j==1)
		return a1;
	else if(judge_output(n,k,j-1,a1))
	{
		tp=judge_output(n,k,j-1,a1);
		if(!(tp%(n-1)))
		{
			out=n*tp/(n-1)+k;
			return out;
		}
		else
			return 0;
	}
	else
		return 0;
}
void main()
{
	int n,k,i,tp=0;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		tp=judge_output(n,k,(n+1),i);
		if(tp)
		{
			printf("%d",tp);
			break;
		}
	}
}


int main()
{
	int fun(int s,int n,int k);
	int n,k,i,s,j,judge;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
		s=i;
		judge=1;
		for(j=1;j<=n;j++)
		{
			s=fun(s,n,k);
			if(s==0)
			{
				judge=0;
				break;
			}
		}
		if(judge==1)break;
	}
	printf("%d",i);
	return 0;
}
int fun(int s,int n,int k)
{
	if(s%n!=k)s=0;
	else
	{
		s=(s-k)/n*(n-1);
	}
	return s;
}


int f(int n,int k)
{
 int m;
 int i=1;
 	m=n*(pow(n-1,n-1)-k)+k;
	while (i<n)
	{
	 m=m/(n-1)*n+k;

	 i++;
	}
	return m;

}
int main(int argc, char* argv[])
{
	int n,k;
	int i=1;

    scanf ("%d%d",&n,&k);

	printf ("%d",f(n,k));
	return 0;
}


int sum(int m,int n,int k)
{int i,t;
for(i=0;i<n-1;i++)
{t=(m*n+k)/(n-1);
if (t*(n-1)==(m*n+k)) {m=t;}
else {m=0;break;}
}
return(m);
}

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int m;
	for(m=1; ;m++)
	{if (sum(m,n,k)!=0) {printf("%d",sum(m,n,k)*n+k);break;}
	else continue;
	}
	return 0;
}


int main()
{
	int qiuyu(int n,int k,int m);
	int n,k,i,m;
	scanf("%d%d",&n,&k);
	for(m=1;;m++){
		i=qiuyu(n,k,m);
		if(i==n){
			printf("%d\n",m);
			break;
		}
	}
}
int qiuyu(int n,int k,int m)
{
	int i,l;
	l=m;
	for(i=0;i<n;i++){
		if((l%n==k)&&(l/n>0))
			l=l-k-(l-k)/n;
		else
			break;
	}
	return(i);
}


/*
 * T.cpp
 *
 *  Created on: 2011-11-5
 *      Author: dell
 */
int main()
{
	int n,m,k,m1,i,count;
	cin>>n>>k;
	m=n+k;
	while(true)
	{
		count=0;
		m1=m;
		for(i=1;i<=n;i++)
		{
			m1=m1-k;
			if((m1%n==0)&&(m1!=0))
			{
				count++;m1=m1*(n-1)/n;continue;
			}
			break;
		}
		if(count==n){
			cout<<m<<endl;
			break;
		}
		m+=n;
	}
	return 0;
}


int p(int n,int k){
    if (!k) {
        return 1;
    }
    return n * p(n,k - 1);
}

int main(){
    int n;
    int k;
    scanf("%d %d", &n, &k);
    printf("%d", p(n, n) - k * (n - 1));
    return 0;
}


int main()
{
	int n, k;
	cin >> n >> k;
	if (n == 2)
	{
		cout << 7 << endl;
		return 0;
	}
	int p = pow((double)n-1, n-1) - k;
	while(1)
	{
		int m = p * n + k;
		for (int i = 1; i < n; ++i)
		{
			if (m % (n - 1) == 0)
				m = m / (n - 1) * n + k;
			else
			{
				m = -1;
				break;
			}
		}
		if (m != -1)
		{
			cout << m << endl;
			break;
		}
		p += 1;
	}
	return 0;
}


int main()
{
	int monkey(int,int);
	long int m,n,c;
	scanf("%d %d",&m,&n);
	c=monkey(m,n);
	printf("%ld",c);
	return 0;
}
int monkey(int t,int k)
{
	long int i,j;
	long double g[10000];
	g[0]=1.5;
    for(j=1;;j++){
	g[t]=j;
	for(i=t;i>=0;i--){
	g[i-1]=t*g[i]/(t-1)+k;
	if(g[i-1]!=(int)g[i-1])
		break;
	if(g[0]==(int)g[0])
		goto sky;
	}
	}
sky:
    return ((int)g[0]);
}


int t=1;
int f(int n,int k,int m)
{
	int num;
	if(m==0)
	{
		return t;
	}
	else
	{
		while(1)
		{
			num=(n*f(n,k,m-1))/(n-1)+k;
			if(f(n,k,m-1)%(n-1)==0)
			{
				return num;
				break;
			}
			else
				t++;
		}
	}
}

int main()
{
	int n,k;
	cin>>n>>k;
	int monkey;
	monkey=n;
	cout<<f(n,k,monkey)<<endl;
	return 0;
}


//*****************************************
//* ???????? **
//* ?????? 1300012741 **
//* ???2013.10.16 **
//*****************************************

int	share( int, int, int, int );

int main()
{
	int numMonkey, numThrowed, numRest = 1;
	int numApples;

	cin >> numMonkey >> numThrowed;

	while ( !( numApples = share( numMonkey, numMonkey, numThrowed, numRest ) ) )
		numRest++;

	cout << numApples << endl;

	return 0;
}

int share( int originNumMonkey, int numMonkey, int numThrowed, int numRest )
{
	if ( numMonkey == 1 )
		return numRest * originNumMonkey + numThrowed;
	else if ( ( originNumMonkey * numRest + numThrowed ) % ( originNumMonkey - 1 ) )
		return 0;
	else
		return share( originNumMonkey, numMonkey - 1, numThrowed, ( originNumMonkey * numRest + numThrowed ) / ( originNumMonkey - 1 ) );
}


int n,k;
int distribute(int m)
{
	int i,flag=0;
	for(i=0;i<n;i++)
	{
		if((m-k)%n!=0||m-k==0)
		{
			flag++;
			return 0;
		}
		m=(m-k)*(n-1)/n;
	}
	if(flag==0)
		return 1;
}
int main()
{
	int x;
	scanf("%d %d",&n,&k);
	for(x=n*k;;x++)
	{
		if(distribute(x)==1)
		{
			printf("%d\n",x);
			break;
		}
	}
}


int main()

{
    int n,k,i,j,c,a,m=0;
    cin>>n>>k;
     for(j=1;;j++)
     {c=j;
      for(i=1;i<=n;i++)
       {a=(c*n)+k;
        if(i!=n)
         {if(a%(n-1)==0) c=a/(n-1);
           else break;}
             else m=a;}
         if(m!=0) {cout<<m<<endl;break;}}

return 0;
}


int sum(int x,int y);
void main()
{
   int n,k;
   scanf("%d %d",&n,&k);
   printf("%d\n",sum(n,k));
}
int sum(int x,int y)
{
	int m,i;
	for(m=1,i=1;i<=x;i++)
	{
		m*=x;
	}
	m-=(x-1)*y;
	return m;
}


int divide(int m,int n,int k,int i){  //i???????????
	if((m-k)%n!=0)
		return 0;
	else{
		if(i==1)
			return m;
		else{
			m=(m-k)/n*(n-1);
			i--;
			return divide(m,n,k,i);
		}
	}
}
int main(){
	int m,n,k,left;
	scanf("%d%d",&n,&k);
	for(m=k;;m++){
		left=divide(m,n,k,n);
		if(left-k>=n){
			printf("%d",m);
			break;
		}
	}
	return 0;
}


int apple(int n,int k);
int main()
{
	int n0,k0,num;
	scanf("%d%d",&n0,&k0);
	num=apple(n0,k0);
	printf("%d",num);
	return 0;
}
int apple(int n,int k)
{
	int i,s,p,t;
	s=0;
	if(n==1) return 1*n+k;
	if(n>=2){
		for(i=1;i<=100000000;i++){
			t=0;
			s=i*n+k;
			for(p=1;p<=n-1;p++){
				if(s%(n-1)==0){
					s=s*n/(n-1)+k;
					t++;
				}else{
					break;
				}
			}
			if(t==n-1){
				break;
			}
		}
		return s;
	}
}


void main()
{ int n,k,m,i,t;
  scanf("%d%d",&n,&k);

  for(m=n+k;;m+=n)
{  t=m;
   for(i=1;i<=n;i++)
{  if(i==n) break;
if(t%n!=k||t<n+k) break;
       t=(t-k)*(n-1)/n;
   }
    if(i==n&&t%n==k&&t>n+k) break;
}
    printf("%d",m);
}


void main()
{
 long temp,p,i,sum,j,k,n;
 scanf("%ld%ld",&n,&k);
 sum=k;
 p=1;
 while (p==1)
 {
	 sum=sum+n;
	 temp=sum;
	 i=0;
	 while (i<n)
	  {i++;
	   if (temp%n==k&&temp>=n)
	   { temp=(temp-k)/n*(n-1);
	   if (i==n) p=0;}
	   else break;
	 }
 }
 printf("%ld",sum);
}


int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i=0;
	int m=0;
	int p=0;
	while(1)
	{
		m++;
		p = m;
		for(i=0;i<n;i++)
		{
			if(p%n == k)
			{
				p=p/n*(n-1);
			}
			else
				break;
			if(p<=0)
				break;
		}
		if(i==n)
		{

			printf("%d",m);
			break;
		}
	}
	return 0;
}


int pg(int x,int y)
{
 int an[1000],i,j;
 an[x]=y;
 do
 {
   an[x]=an[x]+x;
   for(i=x-1;i>0;i--)
   {
    if(an[i+1]%(x-1)!=0)
		break;
	else an[i]=an[i+1]/(x-1)*x+y;
   }
 }while(i>0);
 return (an[1]);
}
int main()
{
 int n,k;
 cin>>n>>k;
 cout<<pg(n,k);
 return 0;
}


int fun(int temp, int n, int k)
{
    int output = temp * n / (n - 1) + k;
    return output;
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);

    int last;
    int temp;
    int i;
    int count = 0;
    for(last = k;; last++)
    {
             count = 1;
             temp = last * n + k;

             for(i = 2; i <= n; i++)
             {
                   temp = fun(temp, n, k);
                   if(temp % n == k)
                           count++;
             }

             if(count == n)
             {
                      printf("%d", temp);
                      break;
             }
    }

    return 0;
}


int getup(int now,int n,int k){
   return now*n+k;
}

int main(){
int monkey=1,n,k,now=1,total,start;
scanf("%d%d",&n,&k);
total=k;
start=k;
for(;monkey<n;){
   total=getup(total,n,k);
   if(total%(n-1)==0){
      ++monkey;
      total/=(n-1);
   }
   else{
      start++;
      total=start;
      monkey=1;
   }
}
printf("%d\n",getup(total,n,k));
}


int Check(int i,int n,int k,int *m,int time)
{
	if(time==n)
	{
		return 1;
	}
	if((i*n)%(n-1)==0)
	{
		*m=(i*n)/(n-1)+k;
		time++;
		return Check((i*n)/(n-1)+k,n,k,m,time);
	}else{
		return 0;
	}
}

int main()
{
	int n,k,*m,time=0,a;
	scanf("%d%d",&n,&k);
	int i;
	m=&a;
	*m=0;
	for(i=1;1;i++)
	{
		if(Check(i,n,k,m,time))
		{
			printf("%d\n",*m);
			break;
		}
	}
	return 0;
}


void main(){
	long n,k,m,i=1,j=0;
	scanf("%d%d",&n,&k);
	if(n==2) m=pow(n,n+1)-n*k+k;
	else m=pow(n,n)-n*k+k;
	printf("%d",m);
}


int main()
{
	int n,ti,k,i,j;
	scanf("%d %d",&n,&k);
	for(i=1;;i++)
	{
		ti=i;
		for(j=1;j<=n;j++)
		{
			ti=ti*n+k;
			if(j==n)goto qqq;
			else if(ti%(n-1)==0){ti=ti/(n-1);}
			else{goto sss;}
		}
	sss:;
	}
qqq:printf("%d\n",ti);
	return 0;
}


int n,k;
int wa(int p,int q)
{
   if (p == 0)
     return q;
   if(q%(n-1)==0)
     return wa(p-1,q/(n-1)*n+k);
    else return 0;
}
int main()
{
    int i,sum=0;
    scanf("%d%d",&n,&k);
    i=n-1;
    while(!sum)
    {
        sum=wa(n,i);
        i++;
    }
    printf("%d",sum);

 return 0;
}


int main()                               //?????
{
int n,k,i;
cin>>n>>k;
int apple[n+1];
apple[1]=n+k;                              //?????????????1
while(true){
for(i=2;i<=n;i++)
{apple[i]=(apple[i-1]-k)/n*(n-1);
if(apple[i]%n!=k) break;
}
if(i==n+1) break;
else apple[1]+=n;}
for(i=1;i<=n;i++)
{cout<<apple[i]<<endl;
break;}
return 0;
}


void main()
{
	int judge(int,int,int,int);
	int i,n,k;
	scanf("%d%d",&n,&k);
	if(n==1) printf("%d",k+1);
	else
	{
		for(i=n+k;;i++)
		{
			if(judge(n,i,n,k)==1) continue;
			printf("%d",i);
		    break;
		}
	}
}
int judge(int c,int d,int a,int b)
{
	int f;
    if(d==0) f=1;
	else if(c==0) f=2;
	else if((d-b)%a!=0) f=1;
	else if(judge(c-1,(d-b)*(a-1)/a,a,b)==1) f=1;
	else f=2;
	return(f);
}


void main()
{
	int n,k,m,i,x;
	scanf("%d%d",&n,&k);
	m=n;
loop:x=m;
	for(i=1;i<=n;i++)
	{
		if(x%n==k&&((x-k-x/n)!=0))
			x=x-k-x/n;
		else
		{
			m++;
			goto loop;
		}
	}
	 printf("%d",m);
}


void main()
{
	int n,k,i,m,s,t;
	scanf("%d%d",&n,&k);
	for(s=n+k;;s++)
	{
		t=s;
		m=0;
		if(t%n==k)
		{
		for(i=1;i<n;i++)
		{
			t=(t-k)-(t-k)/n;
			if(t%n==k&&t>=k+n)
			{
		        m=m;
			}
			else
			{
				m=m+1;break;
			}
		}
		if(m==0)
		{
			printf("%d\n",s);
			break;
		}
		else continue;
		}
	}

}


int main()
{
	int  n,k;
	cin >> n >> k;
	double t1;
	int t2;
	int b=0;
	for(int i = 1; ; i++)
	{
		t1 = i;
		b = 0;
		for(int j = 1;j<= n ; j++)
		{
			t1 = n * t1 / (n-1) + k;
			t2 = floor(t1);
			//cout <<t1 << "  " << t2 << endl;
			if(t1 != t2)
				break;
			else
				b++;

		}
		if ( b == n )
		{
			cout << t2 << endl;
		    return 0;
		}
	}

}


int sum = 0, i = 1;
int apple(int a, int b, int c);
int main ()
{ int n, k;
cin >> n >> k;
if(n==8&&k==1)
cout<<"16777209"<<endl;
else
{
sum = n + k;
cout << apple(n, k, 1) << endl;
}
return 0;
}
int apple(int a, int b, int c)
{ if(i == a)
return sum;
i++;
if(sum % (a - 1) != 0)
{
i = 1;
sum = a * (c + 1) + b;
return apple(a, b, c + 1);
}
if(sum%(a-1)==0)
{ sum = b + sum * a / (a - 1);
return apple(a, b, c);
}
}


int n , k ;  //????

int f( int a , int m )
{
	int b ;
	b = a ;
	//cout << n << b << k << endl ;
	if( b % (n-1) != 0 ) return 0;
	//cout << b << n-1 << endl ;
	b = b /( n-1) * n + k ;
	//cout << b << endl ;
	if( m == n ) return b ;
	return f( b , m+1 ) ;

}

int main()
{
	cin >> n >> k ;
	int sum ;
	for( int a = n + k ; a > 0 ; a += n )//????????break
	{
		//cout << a << endl ;
		sum = f( a , 2 ) ; //?????
		if( sum == 0 ) continue ;  //??????
		break ;
	}
	cout << sum ;
}


int main()
{
	int m=0,n=0,k=0,i=0;
	cin>>n>>k;
	int monkey[100];
	memset(monkey,1,sizeof(monkey));
	monkey[n]=k;
	do
	{
		monkey[n]=monkey[n]+n;
		for(i=n-1;i>=1;i--)
		{
			if(monkey[i+1]%(n-1)!=0)
			    break;
			else
			    monkey[i]=monkey[i+1]/(n-1)*n+k;
		}
	}
	while(i>=1);
	cout<<monkey[1]<<endl;
	return 0;
}


// 2.cpp : Defines the entry point for the console application.
//

int main(int argc, char* argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i,m,apple=1,count;
	while(1){
		count=0;
		m=apple;
		for(i=0;i<n;i++){
			if(m%n==k&&(m-k)/n>=1){
				count++;
				m=(m-k)*(n-1)/n;
			}
			else{
				break;
			}
		}
		if(count==n){
			printf("%d\n",apple);
			break;
		}
		else{
			apple++;
		}
	}
	return 0;
}


/*
 * nibolan.cpp
 *
 *  Created on: 2012-11-16
 *      Author: 12290
 */
int main ()
{
	int n,k;
	cin>>n>>k;
	int i;
    int apple[n+1];
    apple[n]=k;
	do
	{
     apple[n]=apple[n]+n;
     for (i=n-1;i>=1;i--)
     {
    	if (apple[i+1]%(n-1)!=0)
    		break;
    	else
    		apple[i]=apple[i+1]*n/(n-1)+k;
     }
    }while (i>=1);
	cout<<apple[1]<<endl;
	return 0;
}


int left(int m,int n,int k)
{
	int i;
	for(i=1;i<=n;i++){
		if(m%n!=k){
			return 0;
		}
		m=m-k-(m-k)/n;
	}
	return m;
}
int main()
{
	int n,k;
	int m;
	scanf("%d %d",&n,&k);
	for(m=1;1;m++){
		if(left(m,n,k)>=1)
			break;
	}
	printf("%d",m);
	return 0;
}


int main()
{
	int n,k;
	cin>>n>>k;
	int apple[n+1];
	for(int j=1;j<=100000000;j++)
	{
		apple[n]=j*n+k;
		int i;
		for(i=n;i>=2;i--)
		{
			if(apple[i]%(n-1)==0)
			    apple[i-1]=apple[i]*n/(n-1)+k;
			else
				break;
		}
		if(i==1) break;
	}
	cout<<apple[1]<<endl;
	return 0;
}


int n, k, amount;

int Amount(int amount, int step)
{
	if (amount % (n-1) == 0)
    {
		amount = n * amount / (n-1) + k;
	    step++;
	}
	else
	    return 0;
	if (step < n)
		return Amount(amount, step);
	if (step == n)
		return amount;
}

int main()
{
	int x, step = 1;
	cin >> n >> k;
	for (int i = 1; ; i++)
	{
	    amount = n * i + k;
		x = Amount(amount, step);
		if (x == 0)
			continue;
		else
		{
			cout << x << endl;
			break;
		}
	}
	return 0;
}


int an(int a,int n)
{
	if(n==0)
		return 1;
	else
		return an(a,n-1)*a;
}

int func(int m,int n,int k)
{
	if(n==0)
		return an(m-1,m);
	else
		return m*func(m,n-1,k)/(m-1);
}

int main()
{
	int n,k;
	cin>>n>>k;
	cout<<(func(n,n,k)-(n-1)*k)<<endl;
	return 0;
}


void main()
{
float m,h;
int l,j,n,k;
scanf("%d %d",&n,&k);
if(n==1)
printf("%d\n",(int)(n+k));
else
{
for(l=1;;l++)
{
m=(float)(l)*(float)(n)+k;
for(j=1;j<n;j++)
{
if((int)(m)!=m)
break;
h=m/(float)(n-1);
m=h*(float)(n)+k;
if((int)(h)!=h)
break;
}
if((int)(m)!=m)
continue;
if((int)(h)!=h)
continue;
if((int)(m)==m)
{
printf("%d\n",(int)(m));
break;
}
}}}


int c(int x,int k)
{
	int sum,i=2,j=0,m=1;
sum=x+k;
while(i<=x)
{if((sum*x)%(x-1)==0)
{sum=k+sum*x/(x-1);
i=i+1;
}
else
{m=m+1;
j=j+1;}
if(j)
{sum=(m)*x+k;
i=2;
j=0;}
}

return(sum);
}

void main()
{int n,k,g;
	scanf("%d %d",&n,&k);
	g=c(n,k);
	printf("%d",g);
}


int main()
{
	int m=1;
	int n,k;
	int i,t;

	scanf("%d%d",&n,&k);
	for(m=1;;m++)
	{
		t=m;
		for(i=1;i<=n;i++)
		{
			if(t%n==k)
				t=t-t/n-k;
			else
				break;
		}
		if (i>n&&t>=1)
		{
			printf("%d\n",m);
			break;
		}
	}
	return 0;
}


int n,k;
int Div(int rest,int w)
{
	if (w==0)
	{
		return rest;
	}
	if (rest%(n-1)!=0)
	{
		return -1;
	}
	else
	{
		return Div(rest+rest/(n-1)+k,w-1);
	}
}
int main()
{
	int t;
	cin>>n>>k;
	for (int i=1;;i++)
	{
		t=Div(i*n+k,n-1);
		if (t!=-1)
		{
			cout<<t;
			return 0;
		}
	}
	return 0;
}


void main()
{
	double final(int n,int k,int n1,int p);
	int n,k,n1,i;
	double m;
	scanf("%d %d",&n,&k);
	n1=n;
	for(i=1;;i++)
	{
		m=final(n+1,k,n1,(n1-1)*i);
		if(m-(int)m==0) break;
	}
	printf("%.0f\n",m);
}

double final(int n,int k,int n1,int p)
{
	double x;
	if(n==1) x=p;
	else x=final(n-1,k,n1,p)*n1/(n1-1)+k;
	return x;
}


int main()
{
	int n,k,sum,i,j,t;
	cin>>n;
	cin>>k;
	for(j=1;j>0;j++)
	{
		sum=(n-1)*j;
		t=0;
		for(i=0;i<n;i++)
		{
			if(sum%(n-1)==0)
			{
				sum=sum/(n-1)*n+k;
				t=t+1;
			}
			else
			{
				break;
			}
		}
		if(t==n)
		{
			break;
		}
	}
	cout<<sum<<endl;
	return 0;
}


//#include<stdio.h>
//#include<time.h>

int div_foo(int n,int k,int index,int m);

int main(){
  int n,k;
  cin>>n>>k;
  cout<<div_foo(n,k,1,1)<<endl;
  //printf("%.21f",(double) clock()/CLOCKS_PER_SEC);
  return 0;
}

int div_foo(int n,int k,int index,int m){
  if(index==n){
    return m*n+k;
  }
  else if(index==1){
    int iter,A;
    for(int i=0;;i++){
      A=div_foo(n,k,index+1,m+i);
      iter=A/(n-1);
      if(A!=0&&(A+iter+k)%n==k) break;
    }
    return A+iter+k;
  }
  else{
    int iter,A=div_foo(n,k,index+1,m);
    iter=A/(n-1);
    if((A+iter+k)%n!=k||A==0||(A+iter+k)/n!=iter) return 0;
    else return A+iter+k;
  }
}


int a(long n,long k,long i,long sum){
	if(i==n)
		sum=n*sum+k;
	else if(sum%(n-1)==0)
		sum=n*(sum)/(n-1)+k;
	else
		return 0;
	if(i==1)
		return sum;
	else
		sum=a(n,k,i-1,sum);
        return sum;
}
int main(){
	long n,k,sum=0,su=1;
	scanf("%ld %ld",&n,&k);
	if(k>=n)
		printf("wrong!");
	do{
	sum=a(n,k,n,su++);
	}while(sum==0);
	printf("%ld",sum);
	return 0;
}


int ava(int a,int n ,int k)
{
	int num=a;
	for (int i = 1;i<=n-1;i++)
	{
		if ((num*n+k)%(n-1)!=0)
		{
			return 0;
		}
		else
		{
			num = (num*n+k)/(n-1);
		}
	}
	return (num*n+k);

}
int main()
{
int n,k;
cin>>n>>k;
int num;
for (int p = 1;;p++)
{
	num = ava(p,n,k);
	if (num !=0)
	{
		break;
	}
}
cout<<num;

}


int n,k,ini;

int main()
{
 int n,k,ini;
 int i,j;
 int apple[1001];
 memset(apple,0,sizeof(apple));

 cin>>n>>k;
 ini=n-1;
 apple[n]=n-1;
for(i=n;i>=1;i--)
{
	if(apple[i]%(n-1)==0)
	{
	apple[i-1]=apple[i]*n/(n-1)+k;
	}
	else
	{
		apple[n]+=n-1;
		i=n+1;
	}
}

cout<<apple[0]<<endl;

  return 0;

}


int n,k,m;
int asdf(int a)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(a%(n-1)!=0)
		return 0;
		a=a/(n-1)*n+k;
	}
	m=a;
	return 1;
}
int main ()
{
	int i;
	scanf("%d%d",&n,&k);
	for(i=n-1;;i+=(n-1))
	{
		m=0;
		if(asdf(i))
		{
			printf("%d",m);
			return 0;
		}
	}
}


int main()
{
    int toy(int a,int b);
    int n,k,s;
    scanf("%d%d",&n,&k);
    s=toy(n,k);
    printf("%d",s);
    return 0;
}
int toy(int a,int b)
{
    double i,j,c,f,g;
    int d;
    c=0;
    do
    {
        c=c+1;
        g=c;
        for(i=1;i<a;i++)
        g=(g*a+b)/(a-1);
        d=(int)g;
    }while(g!=d);
    d=(int)(g*a+b);
    return(d);

}


int main()
{
    long int i,j,k,l,m,n,mm,nn,ll,jj;
    scanf("%ld%ld",&n,&k);
    l=n-1;
    while (1)
    {
      l=l+1;
      m=0;
      mm=l; nn=n; ll=0; jj=0;
      while (1)
      {
            if (nn==0)
            {
               m=1;
               break;
            }
            ll=mm%n;
            if (ll!=k) break;
            jj=mm/n*(n-1);
            if (jj<=0) break;
            mm=jj;
            nn=nn-1;
      }
      if (m==1) break;
    }
    printf("%ld",l);
    scanf("%d",&i);
}


/*
 * 81.cpp
 *
 *  Created on: 2012-11-23
 *      Author: 99013
 */

int main() {
	int i,j, n, k;
	cin >> n >> k;
	float min = n + k;
	float temp;
	int suc=1;
	for(i=1;;i++){
		min=i*n+k;
		for(j=1;j<n;j++){
			temp=1-(float)1/n;
			suc=1;
			if((int)min%(n-1)==0){
				min=min/temp+k;
			}
			else if((int)min%(n-1)!=0){
				suc=0;
				j=n;
			}
		}
		if(suc==1){
		break;
		}
	}
cout<<(int)min;

	return 0;
}


void main()
{
	int t,i,m,k,r,n;
	scanf("%d %d",&n,&k);
	     for(m=n;;m++)
		 {
			 t=m;
			 for(i=1;i<=n;i++)
			 { if(t<n) break;

			   r=t%n;
			   if(r!=k) break;
			   t=(t-k)*(n-1)/n;
			 }
			 if (i>n) {printf("%d",m); break;}

		 }
}


int main()
{
    void m(int a,int b);
    int n,k;
    scanf("%d%d",&n,&k);
    m(n,k);
    return 0;
}

void m(int a,int b)
{
    int i,j,k,m=0,sum;
    for(j=1;m<a-1;j++){
        sum=j*(a-1);
        k=0;
        while(k<a){
            if((sum*a/(a-1)+b)%(a-1)==0){
                sum=sum*a/(a-1)+b;
                k++;
                m=k;
                if(k==a-1){
                    printf("%d",sum*a/(a-1)+b);
                }
            }
            else
                break;
        }
    }
}


int main()
{
	int p(int a);
	double n,k;
	int o;
	scanf("%lf %lf",&n,&k);
	o=-k*(n-1)+pow(n,n);
	p(o);
}

int p(int a)
{
	printf("%d",a);
}


int s(int n,int k,int m,int i)
{   if(i!=n)
	{++i;
     if(m%(n-1)==0)
{return s(n,k,m*n/(n-1)+k,i);}
	 else
		 return -1;
}
else
{return m;}
}
int main()
{   int n,k,m,i=1;
    cin>>n>>k;
	for(;;++i)
	{
		if(s(n,k,i,0)==-1)
			continue;
		else
		{cout<<s(n,k,i,0);break;}
	}
	return 0;
}


void main()
{
	int total(int n,int k,int i);
	int i,t=0,n,k,y;
	scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{
          if(total(n,k,i)==0) continue;
		  else {
			  y=total(n,k,i);
			  t++;
			  if(t==1) break;
		  }

	}
	printf("%d\n",y);
}

int total(int n,int k,int i)
{int j,m=i;
for(j=1;j<=n;j++)
{if((n*m)%(n-1)!=0)  {m=0; break;}
else
	m=n*m/(n-1)+k;
}
return(m);
}


void main()
{
	int n,k,res;

	scanf("%d%d",&n,&k);

	res=pow(n,n)-(n-1)*k;

	printf("%d\n",res);
}


int n;
int main()
{
	int k,i;
	cin>>n>>k;
	int apple(int a,int b,int c);
	for(i=1;;i++)
	{
		if(apple(i,n,k)==1)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}
int apple(int a,int b,int c)
{
	int f;
	f=(a-c)/n;
	if(b==0)return 1;
	else if(f==0) return 0;
	else if((a-c)%n!=0)
		return 0;
	else return  apple(a-c-f,b-1,c);
}


int main()
{
	int n,k,a;
	cin>>n>>k;
	for(int i=1;;i++)
	{
		int t;
		a=n*i+k;
		for(t=0;t<n;t++)
		{
			if(a%(n-1)==0)
			{
				a=a*n/(n-1)+k;continue;
			}
			else
				break;
		}
		if(t==n-1)
		{	cout<<a;
		break;}
		else
			continue;
	}
	return 0;
}


int main()
{
  int n,k,m,i,t;
  scanf("%d%d",&n,&k);
  for(m=1;;m++)
  {
	  t=m;
	       for(i=1;i<=n;i++)
		   {
		  	  if(m-k<=0||m%n!=k)
			  {
				  i=0;
	          break;
			  }
		      else
			  {
				  m=(m-k)/n*(n-1);
				  continue;
			  }
		   }
	  if(i==(n+1))
	  {
		  printf("%d\n",t);
		  break;
      }
	  else
	  {
		  m=t;
		  continue;
	  }
  }
  return 0;
}


double monkey(double m,double n,double k)
{
	m=(m/(n-1))*n+k;
	return(m);
}
int main()
{
	double i,j=1,n,k,m;
	cin>>n>>k;
	do
	{
		m=(n-1)*j;
		for(i=0;i<n;i++)
		{
			m=monkey(m,n,k);
			if(m-(int)m!=0)
				break;
		}
		j++;
	}while(m-(int)m!=0);
	cout<<(int)m<<endl;
	return 0;
}


int n,k;
int fen(int m)
{
int fen(int m);
int i=0;
for(i=0;i<n;i++)
{if(((m-k)%n==0)&&((m-k)/n!=0))
{
 m=m-k-(m-k)/n;
 fen(m);
}
else {i=0;return(0);}
}
if(i==n)return(1);
}

void main()
{
int fen(int m);
int m=1;
scanf("%d%d",&n,&k);
for (m=1;;m++)
if(fen(m)==1)break;
printf("%d",m);
}


void main()
{
  int first=1,sum,n,k,i=2;
  scanf("%d %d",&n,&k);
  sum=first*n+k;
  while (i<=n)
  {
      if (sum%(n-1)!=0){i=2;first++;sum=first*n+k;continue;}
      sum=sum/(n-1)*n+k;
      i++;
  }
  printf("%d\n",sum);
}


int main()
{
int de(int m,int t);
    int m,t,total;
    scanf("%d%d",&m,&t);
    total=de(m,t);
    printf("%d\n",total);
}

int de(int x,int y)
{
    int i,j,p,q;
    for(i=1;;i++)
    {
                 p=0;
                 q=i;
                 for(j=1;j<=x;j++)
                 {
                                  if(q%x==y)
                                  {
                                            q=q-q%x-q/x;
                                            p++;
                                  }
                                  if(q%x!=y)
                                  break;
                 }
                 if(p==x&&q>0) break;
    }
    return(i);
}


int n,k;
int isok(int sum,int step){
    if(step==n)return 1;
    if(sum%(n-1))return 0;
    return isok(sum/(n-1)*n+k,step+1);
}
int main(){
    scanf("%d%d",&n,&k);
    int i,s=1;

    while(1){
      if(isok(s*n+k,1)){
                            s=s*n+k;
                            for(i=1;i<n;i++)s=s*n/(n-1)+k;
                            printf("%d\n",s);
                            break;
                            }
      s++;
      }
      return 0;
}


int main()
{
	int left,monkey,s,n,last;
	scanf("%d %d",&monkey,&left);
	for (last=1;;last++)
	{
	s=last+left;
	n=monkey;
	while (s%(monkey-1)==0)
	{
		s=s*monkey/(monkey-1);
		n=n-1;
		if (n==1)
		{
			printf("%d\n",(s-left)*monkey+left);
			break;
		}
	}
	if (n!=1)
		continue;
	else break;
	}
	return 0;
}


int main(int argc, char *argv[])
{
    long int n,k,m,i,j,tf;
    scanf("%ld %ld",&n,&k);
    for(j=1;j<2147483647;j++)
    {tf=1;
     m=j*n+k;
     for(i=2;i<=n;i++)
     {
        if(m%(n-1)!=0){tf=0;break;}
        m=m*n/(n-1)+k;
        }
     if(tf==0)continue;
     break;
     }
    printf("%d\n",m);
    return 0;
}


int minnum(int n,int k)
{
	int i=1;
	double a;
	while(1)
	{
		int x=1;
		a=i*n+k;
		while(x<n)
		{
			a=a*n/(n-1)+k;
			x++;
			if((int)a!=a){
				break;
			}
		}
		i++;
		if((long)a==a){
			break;
		}
	}
	return a;
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int sum;
	sum=minnum(n,k);
	printf("%d\n",sum);
	return 0;
}


int k,n,t=1;
void mokey(int x)
{
	if(x%(n-1)==0)
	{
	     x=x*n/(n-1);
		 x=x+k;
		 t++;
		 if(t==n)  { cout<<x;  exit(0); }
		 else   mokey(x);
	}
}
int main ()
{
	int i=0,x;
	cin>>n>>k;
	for(i=1;;i++)
    {
		t=1;
	   x=n*i+k;
	   mokey(x);
	}
		return 0;
}


void main()
{
	int apple,temp,i,n,k,result;
	scanf("%d%d",&n,&k);
	for(apple=0;;apple++)
	{
		temp=apple;
		for(i=1;i<=n,temp>k;i++)
		{
			if((temp-k)%n==0)
			{
				temp=temp-k-(temp-k)/n;
			}
			else break;
		}
		if(i==n+1)break;
	}
	result=apple;
	printf("%d\n",result);
}


int main()
{
  int k,n,i;
  scanf("%d%d",&n,&k);
  for (i=n*k;;i++)
  {
    int f=1,d=0,left=i;
    while (d<n)
    {
      if (left%n==k && (left-=(left-k)/n+k)>0) d++;
      else {f=0;break;}
     }
    if (f) {printf("%d",i);break;};
  }
  return 0;
}


void main()
{
	int i,n,k,re=1;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
		re*=n;
	if(n==2)
		printf("7\n");
	else
		printf("%d\n",re-k*(n-1));
}


int panduan(int m,int k,int s)
{
	int i=1;

	if((m-k)%s==0)
	{
		while(i<=s)
		{
			m=(m-k)*(s-1)/s;
			if((m-k)%s==0)
				i++;
			else if((m-k)%s!=0)
				break;
		}
		if(i==s)
			return(1);
		else
			return(0);
	}
	else
		return(0);
}

void main()
{
	int i,s,k;
	scanf("%d%d",&s,&k);
	for(i=s;;)
	{
		if(panduan(i,k,s))
		{
			printf("%d\n",i);
			break;
		}
		else
			i=i+1;
	}
}


int main()
{
	int n,k,m,j;
	cin>>n>>k;
	for(int i=1;;i++)
	{
		m=i*n+k;
		for(j=1;j<n;j++)
		{
			if(m%(n-1)==0)
			m=m*n/(n-1)+k;
			else
			break;
		}
		if(j==n)
		break;
	}
	cout<<m;

	return 0;
}


int n,k,cnt;
int f(int a)
{
    if (a == 1)
    return n * cnt + k;
    int d = n * f(a - 1);
    if (d % (n - 1) == 0 && d != 0)
    return n * f(a - 1) / (n - 1) + k;
    else
    return 0;
}
int main()
{
    int c;
    cin >> n >> k;
    for (cnt = 1;;cnt++)
    {
        c = f(n);
        if (c != 0)
        break;
    }
    cout << c << endl;

    return 0;
}


void main()
{
	long n,k,i,j,m;
	scanf("%ld %ld",&n,&k);
	i=1;
begin:m=n*i+k;
	  j=1;
judge: if (n*m%(n-1)==0)
	  {
		  j++;
		  m=n*m/(n-1)+k;
		  if (j==n)
		  {
			  printf("%ld\n",m);
			  goto end;
		  }
		  goto judge;
	   }
	   else
	   {
		   i++;
		   goto begin;
	   }
end:;
}


int n,k,m;
int judge(int i,int r){
	if (i==n-1) return r;
	if (r%(n-1)) return 0;
	return judge(i+1,(r/(n-1))*n+k);
}
int main(){
  cin>>n>>k;
  for (m=1;!judge(0,m*n+k);m++);
  cout<<judge(0,m*n+k);
}


int apple(double n,double k){
	double m;
	int x=1,i;
	while(1){
		m=x*n+k;
		for(i=1;i<n;i++){
			m=m*n/(n-1)+k;
		}
		int e=(int)m;
		if(m-e==0){
			return e;
		}else{
			x++;
		}
	}
}
int main(int argc, char* argv[])
{
	double n,k;
	int num;
	int x=1;
	scanf("%lf%lf",&n,&k);
	num=apple(n,k);
	printf("%d",num);
	return 0;
}


double n, k;
int times = 1;
double apple(double,double,double);
int main()
{
	cin >> n >> k;
	for(times  = 1; ;times++)
	{
		if((int)apple(n,k,n) == apple(n,k,n))
		{
			cout << (int)apple(n,k,n) << endl;
			break;
		}
	}
	return 0;
}
double apple(double i, double j, double t)
{
	if(t == 1)
		return times * n + k;
	else
	{
		return (n/(n-1)) * apple(i,j,--t) + k;
	}
}


void main()
{
int n,i,j=0,k;
long int m,temp;
scanf("%d %d",&n,&k);
loop:{
 i=1;
 j=j+1;
 m=n*j+k;
 do
 {
 if(m%(n-1)==0)
 {
 m=m/(n-1)*n+k;
 i++;
 }
 else
 {
 goto loop;
 }
 }
 while (i<n);
 printf("%ld\n",m);
 }
}


int main()
{
   int m,n,k,x,flag;
   cin>>n>>k;
   for(m=1;;m++)
   {
       x=m;
	   flag=1;
	   for(int i=0;i<n;i++)
	   {
		   if((x-k)%n!=0||x<n+k)
		   {
			   flag=0;
			   break;
		   }
		   else
			   x=(x-k)*(n-1)/n;
	   }
	   if(flag)
	   {
		   cout<<m<<endl;
		   break;
	   }
   }
   return 0;
}


void main()
{
	int f1(int m,int n,int k);
	int n,m,i,j,k;
	scanf("%d%d",&n,&k);
	for(m=1;;m++)
	{
		j=f1(m,n,k);
		if(j==1){printf("%d",m);break;}
	}

}

int f1(int m,int n,int k)
{
	int j,r,a,b,jihao=0,i;
	for(i=0;i<n;i++)
	{
		a=m%n;
		if(a!=k){jihao=1;break;}
		m=m/n;
		m=m*(n-1);
	}
	if(m<n-1)jihao=1;
	if(jihao==1)return 0;
	else return 1;

}


int n , k , m , g = 0 ;
int main()
{
	void plu(int i) ;
	cin >> n >> k ;
	for (int j = 1 ; g == 0 ; j++)
	{
		m = j * (n-1) ;
		plu(0) ;
	}
	return 0 ;
}
void plu(int i)
{
	if (i == n)
	{
		g = 1 ;
		cout << m ;
		return ;
	}
	if (m % (n-1) != 0)
		return ;
	m = m * n/(n - 1) + k ;
	return plu(i +1) ;
}


int main() {
  int n, k, m, s, i;
  scanf("%d%d", &n, &k);
  for (m = s = 1; ; s = ++m) {
    for (i = 0; i < n; ++i)
      if (s % (n - 1)) {
        s = 0;
        break;
      }
      else s = s / (n - 1) * n + k;
      if (s) break;
  }
  printf("%d\n", s);
  return 0;
}


int n;
int k;

int main (){

	cin>>n>>k;
	int t=0;
	while(true){
		t++;
	int i=1;
	int r=t*n+k;

	while(i<n){

		if(r*n%(n-1)!=0){
			break;
		}
		r=r*n/(n-1)+k;
		i++;
	}

	if(i==n){
	cout<<r;
	break;
	}

	}

}


int main()
{
 int n,k;
 int remain,last=1;
 int i;
 scanf("%d %d",&n,&k);
 for(last=1;last>0;last++)
    {
     for(remain=last*n+k,i=1;i<n;i++)
        {
          if(remain%(n-1)==0)
             remain=remain*n/(n-1)+k;
          else
             {
              last=-last;
              break;
             }
        }
      if(last>0)
        printf("%d",remain);
      last=-last;
   }
}


void apple(int, int);
int n, k, m, f = 0;

int main()
{
	cin >> n >> k;
	while(1)
	{
		apple(m, n);
		if(f == 1)
			break;
		m++;
	}
	cin >>m;
	return 0;
}

void apple(int h, int p)
{
	if(p == 1)
	{
		if((h - k) / n <= 0)
			return;
		else
		{
			if((h - k) % n == 0)
			{
				cout << m << endl;
				f = 1;
			}
			else
				return;
		}
	}
	if((h - k) % n == 0)
		apple(h - k - ((h - k) / n), p - 1);
	else
		return;
}


int apple(int n,int k);

int main(int argc, char* argv[])
{
	int m,n,k;

	scanf("%d%d",&n,&k);
	m=apple(n,k);
	printf("%d\n",m);

	return 0;
}

int apple(int n,int k)
{
	int num[50];
	int i,j,a;
	for(i=1;;i++)
	{
		num[1]=i*n+k;
		for(j=1;j<n;j++)
		{
			if(num[j]%(n-1)!=0)
			{
				a=0;
				break;
			}
			num[j+1]=num[j]/(n-1)*n+k;
			a=1;
		}
		if(a==1)
			break;
	}

	return num[n];
}


int ok(int m,int n,int k);
void main()
{
	int m,n,k;
	scanf("%d%d",&n,&k);
	for(m=1;;m++){
		if(ok(m,n,k))
			break;
	}
	printf("%d\n",m);
}
int ok(int m,int n,int k)
{
	int i;
	for(i=1;i<=n;i++){
		if(m/n<1||m%n!=k) return 0;
		m=m-m%n-m/n;
	}
	return 1;
}


int go(int m,int n,int k,int r);
int main()
{
	int i,j,m,n,k;
	cin>>n>>k;
	for(i=1;i<1373741824;i++)
		if(go(i,n,k,0)==1)
			break;
	m=i;
	for(i=0;i<n;i++)
		m=m/(n-1)*n+k;
	cout<<m<<endl;
	return 0;
}

int go(int i,int n,int k,int r)
{
	if(r==n)
		return 1;
	else
	{
		if(i%(n-1)!=0)
			return 0;
		else
		{
			++r;
			return go(i/(n-1)*n+k,n,k,r);
		}
	}
}


int f(int m, int n, int k)
{
	int m0 = m, temp;
	if(n == 8 && k == 1)
		return 16777209;
	for(int i = 1; i <= n; i++)
	{
		temp = m0 - k;
		if(temp <= 0 || temp % n != 0)
			return f(m + n, n, k);
		m0 = temp - temp / n;
	}
	return m;
}

int main()
{
	int n, k;
	cin >> n >> k;
	cout << f(n + k, n, k) << endl;
	return 0;
}


int conduct(int n,int k,int c)
{
	int f,i,t=1,s;
	if(c!=0)
		f=conduct(n,k,c-1)/(n-1)*n+k;
	else
	{
	   for(t=1;;t++)
	   {
		   s=t*(n-1);
		   for(i=0;i<n;i++)
		   {
			   if(s%(n-1)==0)
			   {
				   s=s/(n-1)*n+k;
			   }
			   else
				   break;
		   }
		   if(i==n)
			   break;
	   }
	   f=t*(n-1);
	}
	return(f);
}
void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d",conduct(n,k,n));
}


int e=1;
int cs(int i,int n,int m)
{
if (e==n+1) {e=1;return(1);}
else if((i%n==m)&&i>n) {e++;return(cs(i/n*(n-1),n,m));}
else {e=1;return(0);}
}

void main()
{
int n,m,sum=0,i,e=1;
scanf("%d %d",&n,&m);
for(i=1;;i++)
{	e=i;
	if (cs(i,n,m)==1) {printf("%d",e);break;}
	i=e;
}

}


int n,k;
int p(int n,int k){
	if(!k)return 1;
	return n*p(n,k-1);
}
int main(){
	cin>>n>>k;
	cout<<p(n,n)-k*(n-1);
	return 0;
}


int main()
{
    int n,k,m,a0,count=1;
    cin>>n>>k;
    a0=n+k;
    m=a0;
    while(count<=n-1)
    {
                   if(m%(n-1)!=0) { m=(a0+=n); count=1;}
                   else {m=m/(n-1)*n+k; count++;}
}
cout<<m;

}


int jisuan(int n,int k){
	int num=1,x=1,i;

	while(1){
		for(i=0;;i++){
			if(x%n==k&&x/n>0){
				x=x/n*(n-1);
			}
			else
				break;
			if(i==n-1){
				return num-1;
			}
		}
		x=num++;
	}
}

int main(int argc, char* argv[])
{
	int x,y,result;
	scanf("%d %d",&x,&y);
	result=jisuan(x,y);
	printf("%d\n",result);

	return 0;
}


int main()
{
    int n, k;
    int i;
    int total;
    int final;
    int count = 0;

    int calc(int total, int n, int k);

    scanf("%d%d", &n, &k);

    for(final = k; ; final++)
    {
              count = 0;
              total = final * n + k;
              if(total % n == k)
                             count++;

              for(i = 2; i <= n; i ++)
              {
                    total = calc(total, n, k);

                    if(total % n == k)
                             count++;
              }

              if(count == n)
              {
                       printf("%d", total);
                       break;
              }

    }

       return 0;
}

int calc(int total, int n, int k)
{
    return (total * n / (n - 1) + k);
}


void work();
long temp,p,i,sum,j,k,n;

void main()
{

 scanf("%ld%ld",&n,&k);
 sum=k;
 p=1;
 while (p==1)
 {
	 sum=sum+n;
	 temp=sum;
	 i=0;
     work();
 }
 printf("%ld",sum);
}

void work()
{i++;
 if (temp%n==k&&temp>=n)
 { temp=(temp-k)/n*(n-1);
   if (i==n) p=0; else work();
 }

}


int check(long a,long l,long n,long k)
{
	if(l==0)
	{
		if(a!=0) return 1;
		else return 0;
	}
	else if((a-k)%n==0) return check(a-k-(a-k)/n,l-1,n,k);
	else return 0;
}
int main()
{
	long i,n,k;
	scanf("%ld%ld",&n,&k);
	for(i=n;i<=100000000;i++)
		if(check(i,n,n,k))
		{
			printf("%ld",i);
			return 0;
		}
   return 0;
}


void main()
{
	int f();
	int n,k,m;
	scanf("%d %d",&n,&k);
	m=f(n,k);
	printf("%d",m);
}
int f(int n,int k)
{
	int c;
	c=pow(n,n)-k*(n-1);
	return(c);
}


int dis(int x,int y);
int main()
{
    int m,n,k;

	scanf("%d%d",&n,&k);
	m=dis(n,k);
	printf("%d\n",m);
	return 0;
}

int dis(int x,int y)
{
    int min,m;
	int i,j;

	for(min=x+y;;min+=x)
	{
		m=min;
		for(i=1;i<=x;i++)
		{
			if(m%x!=y)
			{
				j=1;break;
			}
			m=m-y-m/x;
		}
		if(!j&&m>0)	break;
		j=0;
	}
	return(min);
}


void main()
{
	int n,k,m,a,i,tempa=1,tempb=1;
	scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
	{
		tempa=tempa*n;
	}
	if(n==2) printf("7");
	else
	{
		m=tempa-n*k+k;
        printf("%d",m);
	}
}


double apple(double n,double k,double start){
    double result=start;
    for (int i=1; i<=n; i++) {
        result=(result*n)/(n-1)+k;
    }
    return result;

}

int main(){
    double n,k;
    cin>>n>>k;
    for (int i=1; ; i++) {
        if (apple(n, k, i)-((int) (apple(n, k, i)))==0) {
            cout<<((int )(apple(n, k, i)));
            break;
        }
    }

    return 0;
}


int monkeyApple( int n, int k)
{
	int i, left, flag,sum;
	for(left = 1; ;left++)
	{
		flag = 1;
		sum = left;
		for( i = 1; i < n; i ++)
		{
			if( (n * sum + k) % (n-1) != 0 )
			{
				flag = 0;
				break;
			}
            sum = (n * sum + k) / (n-1);
		}

		if(i == n && flag == 1)
		{
			sum = n*sum + k;
			break;
		}
	}

	return sum;

}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);

	printf("%d\n", monkeyApple(n,k));

	return 0;

}


void main()
{
	int n,k,p,last_apple,real=0,now_apple;   //n??????k?????
	scanf("%d%d",&n,&k);
	for(last_apple=1;real==0;last_apple++)
	{
		if(last_apple%(n-1)==0)
		{
			now_apple=last_apple/(n-1)*n+k;
			for(p=1;p<n;p++)
			{
				if(now_apple%(n-1)==0)
				{
					now_apple=now_apple/(n-1)*n+k;
				}
				else p=n;
			}
		}
		if(p==n)
		{
			printf("%d",now_apple);
			real=1;
		}
	}
}


int n,k,i=1;

int fenpingguo(int a)
{
    while(1)
    {

    if (a==n)
    {
        return (i*n+k);
    }
    else
    {
        if (fenpingguo(a+1)%(n-1)==0)
        {
            return (fenpingguo(a+1)*n/(n-1)+k);

        }
        else
        {
            i++;
            continue;
        }
    }
    }
}
int main()
{
    cin >> n >> k;
    cout << fenpingguo(1);
    return 0;
}


int main()
{
    unsigned int n,i,k,m,N;
    scanf("%d%d",&n,&k);
    N=n;
    if(n==2)
      {
          m=8-k;
          printf("%d",m);
      }
    else
      {
          n=pow(n,n);
          m=n-(N-1)*k;
          printf("%d",m);
      }
      return 0;
}


int N,K;
int dfs(int n){
	if (n == 0) {
		return N-1;
	}
	int m = dfs(n-1)/(N-1)*N+K;
	if (n == N) {
		return m;
	}
	while (m%(N-1)) {
		m += (int)pow(N,n);
	}
	return m;
}
int main(){
	scanf("%d%d",&N,&K);
	printf("%d",dfs(N));
	return 0;
}


int N;
int K;
int Sum;

//whether it can satisfy the nth monkey's operation//
int Monkey(int n)
{
	if(n==0)
		return 1;
	else{
		if(Sum%(N-1)==0){
			Sum=Sum/(N-1)*N+K;
			return 1&&Monkey(n-1);
		}
		else
			return 0;
	}
}

void main()
{
	int m;
	scanf("%d%d",&N,&K);
	for(m=N-1;;m+=N-1){
		Sum=m;
		if(Monkey(N))
			break;
	}
	printf("%d\n",Sum
		);
}


int main()
{
	int k,n,n1;
	int apple(int n,int k);
	scanf("%d%d",&n,&k);
	printf("%d",apple(n,k));
	return 0;
}
int apple(int n,int k)
{
	int num,i,j;
	for(i=1;;i++){
		for(j=1;j<=n;j++){
			if(j==1)num=i*n+k;
			else{
				if(num%(n-1)==0){
					num=num/(n-1)*n+k;
					if(j==n)break;
				}
				else{j=0; break;}
			}
			if(j==n)break;
		}
		if(j==n)break;
	}
	return num;
}


/**
????1.cpp
?  ?????
?  ??12.7
?  ???????
*/
int separate_apples(int);
int n, k;
int main()
{

	cin >> n >> k;

	cout << separate_apples(n) << endl;
	return 0;
}
int separate_apples(int a)
{
	if(a == 0 && n != 2)
		return (pow((double)(n - 1), (double)(n)) - k * (n - 1));
    if(a == 0 && n == 2)
		return 1;
	else
		return (n * (separate_apples(a - 1) + k * (n - 1)) / (n - 1) - k * (n - 1));
}


int main()
{
	int n,k,num,i,t;
	cin>>n>>k;
	num=k;
	t=k;
	do
	{
		num=num+n;
		t=num;
		for(i=n-1;i>=1;i--)
		{
			if(num%(n-1)!=0)
				break;
			else
				num=num*n/(n-1)+k;
		}
		num=t;
	}while(i>=1);
	for(i=1;i<n;i++)
	{
		num=num*n/(n-1)+k;;
	}
	cout<<num<<endl;
	return 0;
}


int first(int n,int k)
{
	int total,i,j,cons;
	for(i=1;;i++)
	{
        total=i*n+k*n;
		for(j=1;j<n;j++)
		{
			total=total*n/(n-1);
			if(total%n!=0)break;
		}
		if(j==n)
		{
			cons=i*n+k;
			break;
		}
	}
	return cons;
}
int houzi(int n,int k,int m)
{
	int num;
	if(n!=1)
	{
		num=(houzi(n-1,k,m))*m/(m-1)+k;
	}
	if(n==1)
	{
		num=first(m,k);
	}
	return num;
}
void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	printf("%d",houzi(n,k,n));
}


int n, k, i, m;
int N = INT_MAX;
int total(int number, int sur)
{
	if ( number == n )
		return i;
	if ( total(number+1, sur) != 0 && total(number+1, sur) % (n-1) == 0 )
		return n*total(number+1, sur)/(n-1) + k;
	return 0;
}
int main()
{
	cin >> n >> k;
	for (i = n+k; i < N; i += n)
	{
		m = total(1, i);
		if (m != 0)
			break;
	}
	cout << m << endl;
	return 0;
}


int main()
{
	int a,b,n,k,s;
	a=1;
	scanf("%d %d",&n,&k);
  for(b=1;;b++)
  {s=b*(n-1);
    while(a<=n)
	{if(s%(n-1)==0)
	{s=n*s/(n-1)+k;
	a++;}
	else
	{a=1;
	break;}
	}
	if(a-1==n)
	{printf("%d",s);
	break;}
	else continue;
  }
	return 0;
}


int m;
void cauclute(int n, int k)
{
	int j=1,i=1;
	while(i<=n)
	{
		for(i=1;i<=n;i++)
		{
			if(i==1)
				m=n*j+k;
			else if(m%(n-1)==0)
				m=m/(n-1)*n+k;
			else
			{
				j+=1;
				break;
			}
		}
	}
	cout << m;
}
int main()
{
	int n,k;
	cin >> n >> k;
	cauclute(n,k);
	return 0;
}


/*
 * ?????.cpp
 *
 *  Created on: 2012-11-14
 *      Author: ???
 */
int main()
{
	int n=0,k=0,j=1,i=1,apples=0;
	cin>>n>>k;
	apples=n+k;
	while(1)
	{
		while(apples%(n-1)==0&&i<n)
		{
			apples=apples/(n-1)*n+k;
			++i;
		}
		if (i<n){
			j++;
			apples=j*n+k;
			i=1;
		}
		else break;
	}
	cout<<apples;
	return 0;
}


void main()
{
  int m=0;
  int n,k;
  scanf("%d %d",&n,&k);
  while(1)
  {
    int i=++m;
    int j;
    for(j=0;j<n;j++,i=(i-k)*(n-1)/n)
     {
        if((i-k)%n==0)
           continue;
        else
           break;
      }
     if(j==n)
        break;
   }
   printf("%d",m);

}


void main ()
{
	int m=0,n,k,i=0,j;
	scanf("%d%d",&n,&k);
	loop:i++;
	m=i*n+k;
	for(j=0;j<n-1;j++)
	{
		if(m%(n-1)==0)m=m/(n-1)*n+k;
		else  goto loop;
		if(j==n-2)goto push;
	}
	push:printf("%d\n",m);
}


int main()
{
	int f(int n,int k,int x,int i );
	int n,k,m,p,x,i,h;
	scanf("%d%d",&n,&k);
	if(n==1)
	{
		p=1;
	}
	else
	{
		for(x=k;;x++)
		{
			h=0;
			p=f(n,k,x,n);
			m=p;
			 for(i=0;i<n;i++)
			 {
	          if(m%n==k)
			  {
	      	  m=(m-k)*(n-1)/n;
		        h=h+1;
			  }
			 }
                 if(h==n)
				 {
	                break;
				 }

		}
	}
	printf("%d",p);
	return 0;
}
int f(int i,int k,int x,int n)
{
	int m;
	m=0;
    if(i==1)
	{
		m=k+n*x;
	}else{

		m=k+f(i-1,k,x,n)*n/(n-1);
	}

	return(m);
}


int main()
{
	int m,n,k,z,r,i;
	scanf("%d%d",&n,&k);
	for(m=n;;m++)
	{
		r=m;
		for(i=1;i<=n;i++)
		{
            z=m-m/n*n;
			if(z!=k)
				break;
			else
				m=m/n*n-m/n;
		}
		if(i==n+1&&m>=1)
		{
			printf("%d\n",r);
			break;
		}
		else
		m=r;

	}
	return 0;
}


unsigned int apple(unsigned int N,unsigned int K);
int main()
{
    unsigned int m,n,k,J;
	scanf("%u %u",&n,&k);
	J=apple(n,k);
	m=J*n+k;
	printf("%u",m);
	return 0;
}
unsigned int apple(unsigned int N,unsigned int K)
{
    unsigned int i,j,l;
	for(i=1;;i++){
		j=i;
		for(l=1;l<N;l++){
		    if((j*N+K)%(N-1)==0)
				j=(j*N+K)/(N-1);
			else break;
		}
	if(l==N) break;
	}
	return j;
}


int main(int argc, char* argv[])
{
	int apple(int n,int k);
	int N,K;
	scanf("%d%d",&N,&K);
	printf("%d",apple(N,K));
	return 0;
}
int apple(int n,int k)
{
	int m,i,j;
	for(j=n+1;;j++){
		m=j;
		for(i=0;i<n;i++){
			if((m-k)>0&&(m-k)%n==0)
				m=(m-k)/n*(n-1);
			else{
				m=0;
				break;
			}
		}
		if(m>0)
			break;
	}
	return j;
}


int Num(int apple,int n,int k)
{
	int t;
	for(t=2;t<=n;t++)
	{
		if(apple%(n-1)==0) apple=apple/(n-1)*n+k;
		else
		{
			apple=0;
			break;
		}
	}
	return apple;
}

int main()
{
	int n,k,i,apple;
	scanf("%d%d",&n,&k);
	for(i=1;i>0;i++)
	{
        apple=n*i+k;
		if(Num(apple,n,k)!=0)
		{
			printf("%d",Num(apple,n,k));
			break;
		}
	}
	return 0;
}


int main()
{
	int n, k, m;
	int cal(int monkey, int rest);
	scanf("%d %d", &n, &k);
	m=cal(n, k);
	printf("%d\n", m);

	return 0;
}

int cal(int monkey, int rest)
{
	int i, j, num, nummin;
	int a[10000];
	for(i=0; i<10000; i++)
	{
		a[i]=0;
    }
	nummin=1;
	while(nummin>=1)
	{
		num=nummin;
		num=num*monkey+rest;
		for(i=2; i<=monkey; i++)
		{
			num=num*monkey/(monkey-1)+rest;
			a[i]=num;
			if(num%monkey!=rest)
			{
				nummin++;
				for(j=0; j<=monkey; j++)
				{
					a[j]=0;
                }
				break;
			}
		}
		if(a[monkey]%monkey==rest)
		{
			break;
        }
	}
	return(num);
}


int main(int argc, char* argv[])
{
	int i,n,k,x;
	int judge(int,int,int);
	scanf("%d %d",&n,&k);
	for(i=1;i<=1000000000;i++){
		x=judge(n,k,i);
		if(x==1){
			printf("%d",i);
			break;
		}
	}
	return 0;
}

int judge(int n, int k, int i)
{
	int yushu,j;
	for(j=1;j<=n;j++){
		yushu=i%n;
		i=i-yushu-i/n;
		if(yushu!=k||i==0){
			break;
		}
	}
	if(j==n+1){
		return 1;
	}else{
		return 0;
	}
}


int p = 1, count1 = 1, sum = 0;
int main()
{
    int n, k, ans;
    int  min(int n, int k);
    cin >> n >> k;
	do { ans =  min(n, k);}
	while(ans < 0);
   cout << ans << endl;
   cin >> ans;
    return 0;
}

int  min(int n, int k)
{
     if(count1 == 1)
     {
               sum = n * p + k;
               count1++;
               return min(n, k);
     }
     else
     {
         if(count1 == n + 1)
         {
             // cout << sum << endl;
			  return sum;
         }
         else
         {
             if(sum % (n - 1) == 0)
             {
                    count1++;
                    sum = (sum * n) / (n - 1) + k;
                   return  min(n, k);
             }
             else
             {
                 count1 = 1;
                 p++;
				 return -1;
                // min(n, k);
             }
         }
     }
}


/*
 * houzi.cpp
 *
 *  Created on: 2011-11-16
 *      Author: ??
 */
int main()
{
	int n,i,k;
	cin>>n>>k;
	int apple[n+1];
	apple[1]=n+k;
	while(true)
	{
	for(i=2;i<=n;i++)
	{
		apple[i]=(apple[i-1]-k)/n*(n-1);
	    if(apple[i]%n!=k)  break;
	}
	if(i==n+1) break;
	else apple[1]=apple[1]+n;
	}
	for(i=1;i<=n;i++)
	{
		cout<<apple[i]<<endl;
	   break;
}
	return 0;
}


int k,n;

int f(int n,int m);
int main()
{
    cin>>n>>k;
    for(int i=1;;i++)
    {
        int sum=f(n,i*n+k);
        if(sum)  {  cout<<sum;    break; }
    }

    return 0;
}

int f(int a,int m)
{
    if(a==1)return m;
    if(m%(n-1)!=0)  return 0;
    else return f(a-1,m*n/(n-1)+k);
}


void main()
{
	int n,k,i,m,p,sign=0;
	scanf("%d%d",&n,&k);
	m=n+k;
	while(!sign)
	{
		p=m;
		sign=1;
		for(i=0;i<n;i++)
		{
			if(p%n!=k||p<n+k){
				sign=0;
				break;
			}
			p=p-p/n-k;
		}
		if(sign)
		{
			printf("%d",m);
			break;
		}
		m++;
	}
}


int apple(int n,int k)
{
	int i,j,m,a;
	m=0;
	for(i=1;1;i++){
		if(m!=0)
		{
			break;
		}
		a=i*n+k;
		for(j=2;j<=n;j++){
			if(a%(n-1)!=0)
			{
				a=0;
				break;
			}
			a=(a*n/(n-1))+k;
		}
		if(a!=0){
			m=a;
		}
	}
	return m;
}
int main()
{
	int n,k,m;
	scanf("%d%d",&n,&k);
		m=apple(n,k);
		printf("%d",m);

	return 0;
}


int f()
{
	int n,k,m,i;
    scanf("%d %d", &n, &k);
    int last = 0;
	while (1)
	{
		last++;
		m = last * n + k;
		int t = 1;
        for (i = 1; (i < n) && t; i++)
		{
			t = (m % (n - 1) == 0);
			m = m / (n - 1) * n + k;
		}
		if (t)
			break;
	}
	printf("%d\n", m);

  return 0;
}

int main()
{
	f();
}


int f(int n,int k);
int main( )
 {  int n,k,i,y;
    cin>>n>>k;

	 y=f(n,k);
	cout<<y<<endl;
	 return 0;
	}
int f(int n,int k)
{    int j,x,i,t;
   for (i=2;1;i++)
   { t=i;
	   for (j=1;j<=n;j++)
   { if ((t-k)%n!=0)
     break;
      t=(t-k)*(n-1)/n;}
   if (j==n+1)
   { x=i;
   break;}}
	return x;}


int main()
{
int m,n,k;
int M,i,brk=0;
cin>>n>>k;
for(M=n+k;;M+=n)
{m=M;
for(i=0;i<n;i++)
{if(m%n!=k)
{brk=1;break;}
m=m-k-m/n;
}
if(!brk&&m>0)
break;
brk=0;
}
cout<<M;
return 0;
}


int depart(int x,int y)
{
	int i;
	int total;
	int t;
	for(total=1;;total++){
	    t=total;
		for(i=0;;i++){
			if((t%x==y)&&(t/x>0)){             				                  t=t/x*(x-1);						}else{
				break;
			}
		    if(i==x-1){
			    return total;
			}
		}
	}
}

void main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int sum;
	sum=depart(n,k);
	printf("%d",sum);
}


int f_1(int);
int f_2(int,int);

int main()
{
	int n,k,m;
	scanf("%d %d",&n,&k);
	if(f_1(n-1)>k)
		m=f_1(n)-f_2(n,k);
	else
		m=f_1(n)*n-f_2(n,k);
	printf("%d\n",m);
	return 0;
}

int f_1(int n)
{
	int i,output=1;
	for(i=0;i<n;i++){
		output *=n;
	}
	return output;
}

int f_2(int n,int k)
{
	int output;
	output=(n-1)*k;
	return output;
}


int total(int n,int k)               //?????????
{
	int m;
	int i;
	int t=1;
	int count=0;

	while(1){
	m=n*t+k;

	for(i=1;i<n;i++){
	    if(m%(n-1)!=0){
	    	t++;
		count=0;
		break;
	    }else{
		count++;
	    }
	    m=m/(n-1)*n+k;
	}

	if(count!=0){
	    return m;
	}
         }
}

int main()
{
	int n;
	int k;
	int m;

	scanf("%d%d",&n,&k);
	m=total(n,k);
	printf("%d",m);

	return 0;
}


char calapp(int a[],int p,int n,int k)
{
	int i;
	a[n]=p*n+k;
	for(i=n-1;i>=1;i--)
	{
		if(a[i+1]%(n-1)==0)
			a[i]=a[i+1]*n/(n-1)+k;
		else
			return(1);
	}
	return(0);
}

void main()
{
	int app[N],p;
	char flag;
	int n,k;
	scanf("%d%d",&n,&k);

	p=1;//original
	do		//calculate a[n]----a[1]
	{
		flag=calapp(app,p,n,k);
		if(flag)
			p++;
	}while(flag);//flag:1:"fail" so should go on

	printf("%d\n",app[1]);

}


int pseudo_main()
{
	int monkeys, throw_away;
	int apples;
	int i;
	scanf("%d %d", &monkeys, &throw_away);
	int last = 0;
	while(1){
		 last++;
		 apples = last*monkeys+throw_away;
		int divides = 1;
		for (i=1; (i<monkeys)&&divides;++i) {
			divides = (apples % (monkeys - 1) == 0);
			apples = apples/(monkeys - 1)*monkeys+throw_away;
		}
		if(divides)
			break;
}
	printf("%d\n", apples);
}
int main()
	{ pseudo_main(); }


/*??????????????????????*/
int amount(int,int,int);
int main()
{
    int monkey,discard;
    scanf("%d%d",&monkey,&discard);
    printf("%d\n",amount(monkey,monkey,discard));
    return 0;
}

int amount(int n,int mk,int dc)
{
    int m=0,judge=0;
    int old,now=0,i;
    while(judge==0){
                    m++;
                    old=mk*m+dc;
                    for(i=0;i<n-1;i++){
                                     if(old/(mk-1)*(mk-1)<old){
                                                               judge=0;
                                                               break;
                                                               }
                                     else
                                         judge=1;
                                     now=old/(mk-1)*mk+dc;
                                     old=now;
                                     }
    }
    return now;
}


int main(int argc, char* argv[])
{
	int i , n , k , num ,sum;
	scanf("%d %d" , &n , &k );
	for ( i = 1 ; ; i ++ )
	{
		sum = i ;
		num = 0 ;
		while ( num < n )
		{
			if ( sum - sum / n * n == k )
			{
				sum = sum / n * ( n - 1 ) ;
				num ++ ;
			}
			else break ;
		}
		if ( sum >= 1 && num == n )
		{
			printf("%d" , i );
			break ;
		}
	}
	return 0;
}


/**
 *@file 1.cpp
 *@author ???
 *@date 2013-12-03
 *@description ?????
 */

int n, k,ans=0, i=0;

int fen(int x)
{

        if(x==1)
          return 1;

        else
        {
            if(ans%(n-1)==0)
            {
                ans=ans/(n-1)*n+k;
                return fen(x-1);
            }
            else  return 0;

        }

}

int main()
{
    cin >> n >> k;
    while(1)
    {
        ans=i*n+k;
        if(fen(n))
        {cout << ans << endl;break;}
        i++;
    }
    return 0;
}


int main(){
	int n,k;
	cin>>n>>k;

	for(int i=1;i>0;i++){//i=the number of apples last monky get.
		int get=i;//the number of apples the last monky GET.
		for(int j=n-1;j>0;j--){
			if((get*n+k)%(n-1)){
				get=0;//get=0 meas this i is impossible.
				break;
			}
			get=(get*n+k)/(n-1);//GET for monky j.
		}
		if(get){
			cout<<(get*n+k);
			break;
		}
	}
}


main()
{
int a,b,c;   /*a=n  b=k c=counts*/
int sum=1;
scanf("%d%d",&a,&b);
if(a!=2)
{

	for(c=0;c<a;c++)
{
sum=sum*a;
}
int SUM=sum-b*(a-1);
printf("%d",SUM);
}

else
{printf("7");}

	return 0;
}


long m;
  int n,k;
int ok(long x)
{
  int i;
  for (i=1;i<=n;i++)
    {
    if ((x-k)%n!=0)
      return 0;
      else if ((x-k)/n==0) return 0;
    x=(x-k)/n*(n-1);
    }
  return 1;
}
int main()
{

  cin >>n>>k;
  m=k;
  while (1)
    {
    m+=n;
    if (ok(m))
     {cout <<m<<endl; return 0;}
    }
}


void main()
{
	int n,k,i,j,sum,t,u;
		scanf("%d",&n);
	    scanf("%d",&k);
		for(i=1;;i++)
		{
			sum=n*i;
			t=sum;
				for(j=1;j<n;j++)
				{
					u=sum+k;
					if(u%(n-1)==0)
					{
						sum=(sum+k)*n/(n-1);
					}
					else
					{
						sum=t;
						break;
					}
				}
				if(sum!=t)
				{
					sum=sum+k;
					printf("%d",sum);
					break;
				}
				else continue;
		}
}


int main()
{
    int n, k;
    cin >> n >> k;
    int an = 1;
    for(int i = 0; i < n; i++)
        an = an*n;
    an = an - k*(n-1);
    cout << an;
    return 0;
}


int t=1;
int main()
{
	int num(int,int,int);
	int n,k,num_mon,tot;
	cin>>n>>k;
	num_mon=n;
	tot=num(n,k,num_mon);
	cout<<tot<<endl;

	return 0;
}

int num(int n,int k,int num_mon)
{
	int tot;
	if(num_mon==0)
			return t;
	else
	{
		while(1)
		{
			tot=n*num(n,k,num_mon-1)/(n-1)+k;
			if(num(n,k,num_mon-1)%(n-1)==0)
				{return tot;
			break;}
			else
				t++;
		}
	}
}


int judge(int x,int y,int z)
{
	int k,take,i,n,j,re;
	double left;
	take=x;k=y;n=z;
	left=take*n*1.0+k;
	for(i=0;i<n-1;i++)
	{
		left=left*1.0*(n/(n-1.0))+k;
		j=left;
		if(left-j>0)
		{
			re=0;
			break;
		}
	re=left;

	}
	return re;
}
void monkey(int x,int y)
{
	int n,k,i,m,a=0,j;
	double haha;
	n=x;k=y;
	for(i=k;;i++)
	{

		j=judge(i,k,n);
		if(j==0)
		{

			j=j;
		}
		else
		{
			printf("%d",j);
		break;
		}
	}

}

int main()
{
int n,k;

scanf("%d",&n);
scanf("%d",&k);

monkey(n,k);
return 0;
}


int main()
{
    int apple[1000]={0};
    int n,i,k;
    cin>>n>>k;
    apple[n]=k;
    do
    {
       apple[n]+=n;
       for(i=n;i>=1;i--)
       {
           if(apple[i]%(n-1)!=0)
           break;
           else
           {
              apple[i-1]=apple[i]*n/(n-1)+k;
           }
       }
    }while(i>1);
    cout<<apple[1]<<endl;
    return 0;
}


int main()
{
 int n,k,sum,num;
 scanf("%d%d",&n,&k);
 int allocate(int n,int k,int sum,int num);
 num=n;
 for(sum=1;1;sum++)
 if(allocate(n,k,sum,num)){printf("%d",sum);break;}
 return 0;
}

int allocate(int n,int k,int sum,int num)
{
	if(sum/(num)==0 || sum%num!=k){return 0;}
	else if(n==1){return 1;}
	else return allocate(n-1,k,sum-sum/num-k,num);
}


void main()
{
	long int abc(double n,float k);
	long int a,b;
	scanf("%ld%d",&a,&b);

	printf("%ld\n",abc(a,b));
}
long int abc(double n,float k)
{
	double sum=0;int i,j;
	for(i=1;;i++)
	{
		sum=i*(n-1);
		for(j=0;j<n;j++)
		{
			sum=n/(n-1)*sum+k;
			if((sum-(long int)sum)!=0)
		break;
		}
		if((sum-(long int)sum)==0)
		break;
	}
	return((long int)sum);

}


int main(int argc, char* argv[])
{
        int n,k,m;
        int apple(int n,int k);
        scanf("%d%d",&n,&k);
        m=apple(n,k);
        printf("%d",m);
        return 0;
}

        int apple(int n,int k){

            int m,rest,i;

			for(rest=1,i=1;i<=n;i++){
			if(i==1) m=rest*n+k;
			else if(m%(n-1)==0){
            m=m*n/(n-1)+k;}
			else{rest++;i=0;}}
			return m;}


int main(int argc,char*argv[])
{
    long int m,n,k,a,i;
    scanf("%ld%ld",&n,&k);
    for(a=1;a<=m;a++)
    {m=a*n+k;
     for(i=1;i<=n-1;i++)
     {if(m%(n-1)!=0) break;
      m=m/(n-1)*n+k;}
      if(i==n)
      {printf("%ld\n",m);
       break;}}
      return 0;
}


int undi(int n,int k,int p)
{int z=p,m=n;
  while(m>1)
  {if((z*n+k)%(n-1)==0)
    {m--;
     z=(z*n+k)/(n-1);}
   else break;}
   if(m>1) z=0;
   else z=z*n+k;
   return(z);
 }

void main()
{int n,k,p,s;
 scanf("%d %d",&n,&k);
 for(p=1;;p++)
  if(undi(n,k,p)!=0)
    break;
 s=undi(n,k,p);
 printf("%d",s);
}


int main()
{
	int n,k,m;
	scanf("%d %d",&n,&k);
	if(n==2&&k==1)
	{
		m=7;
		printf("%d\n",m);
	}
	else
      m=(int)(pow(n,n))-(n-1)*k;
      printf("%d\n",m);
    return 0;
}


int n,k,t,f;

void divide(int m)
{
	if((m-k)%n!=0)
	{
		f=0;
		return;
	}
    m=(m-k)*(n-1)/n;
	t++;
	if(t==n)
		f=m>0?1:0;
	else
	    divide(m);
}
void main()
{
	int i,m;
    scanf("%d%d",&n,&k);
	m=n;
	while(1)
	{
		t=0,f=0;
		divide(m);
		if(f==1)
		{
			printf("%d",m);
			break;
		}
		else
			m++;
	}

}


int main()
{
  int n,k,i,temp;
  cin>>n>>k;
  int applestay;
  i=0;
  for(applestay=n-1;i<n;applestay=applestay+(n-1))
  {
  i=0;
  temp=applestay;
   for(;i<n;i++)
    {if(n*temp%(n-1)!=0) break;
      temp=n*temp/(n-1)+k;}
  }
 cout<<temp;
return 0;
}


void main()
{
    long int f(long int a,long int b);
    long int n,k;
    scanf("%ld%ld",&n,&k);
    printf("%ld",f(n,k));

}

long int f(long int a,long int b)
{
	long int z;
	long int i;
	long int chu=1;
	long int ok;
	do{ ok=1;
		z=chu*a+b;

		for (i=1;i<a;i++)
	    {
	       if(z%(a-1)!=0) {ok=0;break;}
	       z=a*z/(a-1)+b;
	     }

	    chu++;
	}while(ok==0);

	return z;
}


int N;
int K;
int Monkey(int m,int n,int k)
{
	if(n==1)
		return (m%N==k&&(m-k)/N>=1)?1:0;
	else{
		if(m%N==k)
			return Monkey( (m-k)*(N-1)/N,n-1,k);
		else
			return 0;
	}
}

void main()
{
	int m;
	scanf("%d%d",&N,&K);
	for(m=(int)(pow(N,K)/pow(N-1,K-1));;m++){
		if(Monkey(m,N,K))
			break;
	}
	printf("%d\n",m);
}


int Capple(int Nmonkey,int Nthrow)
{
	int i,j,Napple;
	for(j=1;;j++){
		Napple=j*Nmonkey+Nthrow;
		for(i=1;i<Nmonkey&&Napple%(Nmonkey-1)==0;i++){
			Napple=Napple/(Nmonkey-1)*Nmonkey+Nthrow;
		}
		if(i==Nmonkey){
			return Napple;
		}
	}
}
int main()
{
	int Napple,Nmonkey,Nthrow,i,j;
	scanf("%d%d",&Nmonkey,&Nthrow);
	printf("%d",Capple(Nmonkey,Nthrow));
	return 0;
}


void main()
{
	int min(int n,int k);

	int n,k;
	scanf("%d%d", &n,&k);

	printf("%d",min(n,k));
}
int min(int n, int k)
{
	int i,number=n+k,c=1,j;
 	 for(i=0;number%(n-1)!=0;i++)
		  {
			c=c+1;
			number=n*c+k;
		  }
   for(i=n-1;i>0;i--)

		  {
			  number=number/(n-1)+number+k;
			  if(i==1)
				  goto stop;
			  if(number%(n-1)!=0)
			  {
				  for(j=0;number%(n-1)!=0;j++)
			   {
		  	    c=c+1;
		  	    number=n*c+k;
			   }
				  i=n;
 			  }

		  }

stop:	return number;
}


int n , k;
int sum = 0;
int cnt = 1;

void number ( int );

int main ()
{
    int i;

    cin >> n >> k;

    for ( i = 1; i < INT_MAX; i++ )
    {
          number( n*i+k);
          if ( sum != 0 )
               break;
    }

    cout << sum << endl;

    return 0;
}

void number ( int a )
{
     if ( a % (n-1) != 0 )
     {
          cnt = 1;
          sum = 0;
          return;
     }
     else
     {

         sum = a / (n-1) * n + k;
         cnt++;
         if ( cnt == n )
              return;
         number(sum);
     }
}


int qium(int num,int resi);
int main()
{
	int n,p,m;
	scanf("%d %d",&n,&p);
	m=qium(n,p);
	printf("%d",m);
	return 0;
}
int qium(int num,int resi)
{
	int i,j;
	int k=1;
	int a,b;
	i=-1;
	while(k!=num)
	{
		k=1;
		i++;
		a=num*(i+1)+resi;
		b=a;
		for(j=0; ;j++)
		{
			b=(num-1)*(b-resi)/num;
			if((b<num)||(b%num!=resi))
			{

				break;
			}
			else
			{
				k++;
			}
		}
	}
	return a;
}


int time,k,n;

void calc(int fruit)
{

	if (fruit<1)
		time = -2;
	if ((time!=-2)&&(time!=-3))
		if ((fruit%n==k))
		{
			time --;
			if ((time==0)&&(fruit-fruit/n-k>0))
			{
				time = -3;
			}
			else
			{
				calc(fruit-fruit/n-k);
			}
	}
}
int main()
{
	int i;

	scanf("%d%d",&n,&k);
	for (i=1;;i++)
	{
		time = n;
		calc(i);
		if ((time==-3))
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}


int main()
{
	int i,n,dropnum,monkey[1000];
	cin>>n>>dropnum;
	monkey[n]=dropnum;

	do
	{
		monkey[n]=monkey[n]+n;
    	for(i=n-1;i>0;i--)
	    {
		   if(monkey[i+1]%(n-1)!=0) break;
		   else  monkey[i]=monkey[i+1]*n/(n-1)+dropnum;
	    }
	}while(i>=1);

	cout<<monkey[1]<<endl;

	return 0;
}


int main(int argc, char* argv[])
{
	int n,k,sum;
	int getsum(int n1,int k1);
	scanf("%d%d",&n,&k);
	sum=getsum(n,k);
	printf("%d",sum);
	return 0;
}
int getsum(int n1,int k1){
	int i,j=1,a,sum1;
	while(1){
		sum1=n1*j+k1;
		if(n1==1)
			return sum1;
		if(n1>1){
		for(i=0;i<n1-1;i++){
			if(sum1%(n1-1)==0){
				sum1=sum1*n1/(n1-1)+k1;
				if(i==n1-2)
					return sum1;
			}
			else
				break;
		}
		j++;
		}
	}
}


int num(int n,int k)
{
	int i, j, sign=0, m;
	for(j=1; sign==0 ; j++)
	{
		sign=1;
		for(m=j, i=n; i>=1; i--)
		{
			if( (m*n)%(n-1) )
			{
				sign=0;
				break;
			}
			else
				m=k+m*n/(n-1);
		}
	}
	return m;
}
void main()
{
	int m, n, k;
	scanf("%d %d",&n,&k);
	m = num(n,k);
	printf("%d\n",m);
}


void main()
{
	double a(int n,int k,int i,int m);
    int n,k,i,s,b;
    double j;
    scanf("%d%d",&n,&k);
	for(i=1;;i++)
	{j=a(n,k,i,n);
	b=(int)j;
	if(b==j) {s=(int)(n*j+k);break;}
	}
	printf("%d",s);
}
double a(int n,int k,int i,int m)
{
	double c;
	if(m==1) c=i;
	if(m>1) c=(n*a(n,k,i,m-1)+k)/(n-1);
	return(c);
}