#include<stdio.h>
int main()
{
    int n,m,i,count=0,a=0;
    scanf("%d %d",&n,&m);

    if(n==m){
            printf("%d",n+1);
    }

    if(n<m){
            printf("%d",n);
    }

    if(n>m){
    for(i=1;i<=n;i++){
        if(i%m==0){
            n++;
            count++;
        }
        else count++;
    }
    printf("%d",count);
    }
}

#include<stdio.h>
int main(){
    int i,s,r,l,j,n;
    scanf("%d %d",&n,&j);
    l=n/j;
    r=n%j;
    for(;;){
        if(l==0) break;
        n=n+l;
        s=l%j;
        l=l/j;
        r=r+s;

    }
    if(r>j) n=n+((r/j));
    if(n%j==0) printf("%d",n+1);
    else printf("%d",n);
}

        #include <stdio.h>

        int main(){
            int p,n,m;
            scanf("%i %i",&n,&m);
            int q=n;
            while(n/m>0){
                p=n/m;
                q+=p;
                n=n%m+p;
            }
            printf("%i",q);
        }

#include<stdio.h>
int main()
{
int n,m,c,r,x;
scanf("%d %d",&n,&m);
c=n;
while((n/m)>=1)
{x=n%m;
c=c + n/m;
if(x==0)
n=n/m;
if(x!=0)
{
n=n/m + x;}}
printf("%d",c);
return 0;}

#include <stdio.h>

int main()
{
    int n, m, answer;
    scanf("%d %d", &n, &m);
    if (n<1 || n>100 || m<2 || m>100) n = 0;
    answer = n;
    while (n>=m)
    {
        answer += n/m;
        n = n/m + n%m;
    }
    printf("%d", answer);
}

#include<stdio.h>

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

#include<stdio.h>
int main (){
	int n, m;
	scanf("%d %d", &n, &m);
	int i, count = 0;
	for(i = 1; 0 <(n + count); i++){
		n--;
		if(i % m == 0) count++;
	}
	printf("%d", --i);
}

#include<stdio.h>

int main()
{
	int n, m;
	while (~scanf("%d %d", &n, &m))
	{
		int cnt = 0, day = 0;
		while (n)
		{
			n--;
			cnt++;
			if (cnt == m)
			{
				n++;
				cnt = 0;
			}
			day++;
		}
		printf("%d\n", day);
	}
	return 0;
}

#include<stdio.h>
int main(){
int n,m,d=0;
scanf("%d%d",&n,&m);
while(n/m>0){
d+=n-n%m;
n=(n/m)+(n%m);
}
d+=n;
printf("%d",d);
return 0;
}

#include<stdio.h>

int main()
{
    int m,n,j,a,b,c;

    scanf("%d %d",&m,&n);
    a=1;
    b=m;
    for(;a<b;)
    {
        c=0;
        for(j=a;j<=b;j++)
        {
        if(j%n==0)
        c++;
        }
        a=b+1;
        b=b+c;

    }
    if(b%n==0)

     printf("%d",b+1);
     else printf("%d",b);

    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,days =  0;
    scanf("%d%d",&n,&m);
    while(n >= m)
    {
        int remainder = n%m;
        days += n - remainder;
        n /= m;
        n += remainder;
    }
    days += n;
    printf("%d\n",days);
    return 0;
}

#include <stdio.h>
#include <string.h>

int main()
{
   int i,a,b,n,m;
   scanf("%d %d",&n,&m);
   i=n;
   while(1)
   {
       if(n<m) break;
       else{a=n/m;b=n%m;
       i=i+a;n=a+b;
       }
   }
   printf("%d",i);
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
	int n,m,a,b,k,count,j;
	scanf("%d%d",&n,&m);
	 j=-1;
	count=0;
	a=n+1;
    b=n+n/m;
    while(1)
    {
      for(k=a;k<=b;k++)
      {
      	if(k%m==0)
      	count++;
      }
      a=a+n*pow(m,j);
      b=b+n*pow(m,j-1);
      j--;
      if(a>b)
      break;
    }
    if((n+n/m+count)%m==0)
    printf("%d",n+n/m+count+1);
    else
    printf("%d",n+n/m+count);
}

    #include<stdio.h>
    int main()
    {
        int n, m, x, a;
        scanf("%d %d", &n, &m);
        x=n;
        while(1)
        {
            a=n/m;
            n=a+(n%m);
            x+=a;
            if(n<m)
                break;
        }
        printf("%d", x);
        return 0;
    }

#include<stdio.h>
int main()
{
    int n,m,sum,i,j,d;
    scanf("%d %d",&n,&m);
    sum=0;

    for(i=n;i>=m;i=i/m+i%m)
    {
        sum=sum+(i/m)*m;
    }
    d=sum+i;
    printf("%d\n",d);
    return 0;
}

#include <stdio.h>
int main()
{
	int n,m,d,aux;
	scanf("%d%d",&n,&m);
	d = 0;
	do
	{
		aux = n;
		n -= m;
		if (n < 0)
		{
			d += aux;
			break;
		}
		d += m;
		n++;
	}
	while (1);
	printf("%d",d);
	return 0;
}

#include<stdio.h>

int main(){
        int n,m, sum = 0;
        scanf("%d %d",&n, &m);
        while( n >0){
                n --;
                sum ++;
                if( sum != 0 && sum % m == 0)
                        n ++;
                }

        /*if ((n/m) != 0 && (n/m) % m == 0)
                sum = n + (n/m) + 1;
        else
                sum = n + (n/m);*/
        printf("%d",sum);
        return 0;
}

#include<stdio.h>
int main()
{
    int a, n, m, i, sum=0, repeat;
    scanf("%d %d", &n, &m);
    sum = n + n/(m-1);
    if(n%(m-1) == 0){
        sum -= 1;
    }
    printf("%d", sum);

    return 0;
}

#include<stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int temp=n,count=0;
    while(temp>1&&n>=m){
        temp=temp-m+1;
        count++;
        if(temp<m)break;
    }
    printf("%d\n",n+count);
    return 0;
}

#include<stdio.h>
int main(void)
{
    int n,t,m,c,k;
    scanf("%d",&n);
    t=n;
    c=0;
    scanf("%d",&m);
    while(n/m!=0)
    {
        k=n%m;
        n=n/m;
        c=c+n;
        n=n+k;
    }
    printf("%d",c+t);
    return 0;
}

#include <stdio.h>
int main()
{
   int n,m;
   int i;
   int count = 0;
   scanf("%d %d",&n,&m);
   for(i = 1; ; i++)
   {
      if(i%m == 0)
        count++;
      if(i>n)
      {
          count--;
          }
          if(count == 0 && i>=n)
          break;
      }
      printf("%d\n",i);
      return 0;

   }

#include<stdio.h>
int main()
{
    long n,m,s;
    scanf("%d%d",&n, &m);
    s=n;
    while(n>=m)
    {
        s+=n/m;
        n=n%m+n/m;
    }
    printf("%d\n",s);
    return 0;
}

#include<stdio.h>

int main()

{
	int i=0,n,m;
	scanf("%d%d",&n,&m);
	printf("%d",n+((n-1)/(m-1)));
	return 0;

}

#include <stdio.h>
main()
{
    int n,m,a=0;
    scanf("%d %d",&n,&m);
    while(n>0)
    {
    	a=a+1;
    	if(a%m==0)
    	{
    		n=n;
		}
		else
		{
			n=n-1;
		}
	}
	printf("%d",a);

}

#include<stdio.h>
int main(int argc, char const *argv[]) {
  int a,b;
  scanf("%d %d", &a,&b);
  printf("%d\n", (a*b-1)/(b-1));
  return 0;
}

#include <stdio.h>

int main(void) {
	// your code goes here
	int n,m,i;
	scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
    {
        if(i%m==0)
        n=n+1;
    }
	printf("%d",i-1);
	return 0;
}

#include<stdio.h>
main()
{

int  n,m;
int p,s;
scanf("%d%d",&n,&m);
p=n;
while(n>=m)
{p=p+(n/m);

s=n-(n/m)*m;
n=s+(n/m);
//printf("%d # %d",p,n);
}
printf("%d",p);
}

#include<stdio.h>
int main()
{
    int n,m,cnt=0;
    scanf("%d %d",&n,&m);
    for(int i=0;n>=0;i++,n--)
    {
        cnt++;
        if(i==m)
        {
            n++;
            i=0;
        }
    }
    printf("%d",cnt-1);
    return 0;
}

#include<stdio.h>

int main(){
	int n=0,m=0,DIAS=0,CANT=0,C=0;
	scanf("%d %d",&n,&m);
	CANT=n;
	while(CANT > 0){
		C=C+1;
		CANT=CANT-1;
		DIAS=DIAS+1;
		if(DIAS%m==0){
			CANT = CANT + 1;
		}
	}
	printf("%d",C);
	return 0;
}

#include<stdio.h>

int main(){
	int n=0,m=0,DIAS=0,CANT=0,C=0;
	scanf("%d %d",&n,&m);
	CANT=n;
	while(CANT > 0){
		C=C+1;
		CANT=CANT-1;
		DIAS=DIAS+1;
		if(DIAS == m){
			CANT = CANT + 1;
			DIAS=0;
		}
	}
	printf("%d",C);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n = 0, m = 0, ans = 0, total = 0, additional = 1;
    scanf("%d %d", &n, &m);
    ans += n;
    while(additional != 0)
    {
        additional = 0;
        while(n/m != 0)
        {
            additional += n%m;
            n /= m;
            ans += n;
            //printf("aa %d %d ", n, n%m);
            //printf("%d\n", additional);
        }
        additional += additional+n%m >= m? n%m: 0;
        n = additional;
        total += additional;
    }
    //printf("%d\n", total);
    printf("%d", ans+additional/m);
}

#include <stdio.h>

int main()
{
    int n,m,sum=0,div,check,count=0,res;
    scanf("%d %d",&n,&m);
    sum=n;
    div=sum/m;
    res=sum%m;
    sum=sum+div;
    div=div+res;
    while(1){
        res=div%m;
        div=div/m;
        sum=sum+div;
        div=div+res;
        if(div<m)
            break;
    }
    printf("%d",sum);
    return 0;
}

//
//  main.c
//  jsd
//
//  Created by Mihai Esanu on 10/5/19.
//  Copyright © 2019 Mihai Esanu. All rights reserved.
//

#include <stdio.h>

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

    scanf("%d %d", &n, &m);
    day = 0;
    while(1==1)
        {
            n = n - 1;

            day = day + 1;
        if( day % m == 0 )
        {
            n = n + 1;
        }
            if(n == 0)
            {
                break;
            }
        }

    printf("%d", day);
    return 0;
}

#include <stdio.h>
int main()
{
	int m,n,pairs,temp;
	scanf("%d%d",&m,&n);
	pairs=m;
	while(m/n!=0){
		temp=m/n;
		pairs=pairs+temp;
		m=temp+m%n;
	}
	printf("%d",pairs);
	return 0;
}

#include<stdio.h>
int main()
{
    int n,m,x;

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

if(n==m)

{

x=((n*m)+n)/n;

}

else if(n<m)

{

x=(n*m)/m;

}

else

{

x=((n-1)/(m-1))+n;

}

printf("%d\n",x);

}

#include<stdio.h>
int main()
{

    int n,m,i=1,flag=1,temp,count=0;
    scanf("%d%d",&n,&m);
    int c=n+1;
    int d=n+n/m;

        while(flag)
        {
            flag=0;
            temp=count;
            for(i=c; i<=d; i++)
            {

                if(i%m==0)
                {
                    count++;
                    flag=1;
                }

            }
            c=d+1;
            d=d+count-temp;
        }
       printf("%d",n+n/m+count);

    return 0;

}

#include <stdio.h>
int main ()
{
int n,m,x,y,z,s,a;
s=0;
scanf ("%d %d", &n,&m);
s=s+n;
x=(int)n/m;
s=s+x;
y=x*m;
z=n-y;
x=x+z;
while(x >= m)
{
n=x;
x=(int)x/m;
s=s+x;
y=x*m;
z=n-y;
x=x+z;
}
printf ("%d\n", s);
return 0;
}

#include<stdio.h>
int main()
{
    int a,b,c=0,d,i=2;
    scanf("%d %d",&a,&b);
    d=b;
    while(a>=d)
    {
        c=0;
        while(1)
        {
            if(d<=a){
                c++;
                d=b*i;
                i++;
                }
            else break;
        }
        a=a+c;
    }
    printf("%d",a);
    return 0;
}

#include<stdio.h>
int main(){
    int n,m,i;
    scanf("%d%d",&n,&m);
    for(i=0,n-=1;n>=0;i++){
        if(i%m)
            n--;
    }
    printf("%d",i-1);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,sum,d;
    scanf("%d %d",&n,&m);
    sum=n;
    rich:
    d=n/m;
    if(d>0)
    {
    sum=sum+d;
    if(((n%m)+d)>=m)
    {
    n=(n%m)+d;
    goto rich;
    }
    }
    printf("%d",sum);
    return 0;
}

#include <stdio.h>

int main() {
	int n, m, dia=0;

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

	while(n>0) {
		++dia;
		--n;
		if((dia)%m==0) ++n;
	}

	printf("%d", dia);
	return 0;
}

#include<stdio.h>
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    int a, b, div, mod;
    sf("%d%d", &a, &b);
    int sum = a;
    while(a>=b)
    {
        div = (a/b);
        sum = sum + div;
        mod = (a%b);
        a= (div+mod);
    }
    pf("%d\n", sum);
}

#include<stdio.h>
int main(){
    int n,m,count=0;
    scanf("%d %d",&n,&m);
    while(n>m){
        n = n-(m-1);
        count+=m;
    }
    if(n==m)
        printf("%d",count+n+1);
    else
        printf("%d",count+n);
    return 0;
}

#include<stdio.h>
int main ()
{
    int m,n,a, b, x,i;

    scanf("%d %d",&n, &m);
    x=n;
    for (i=1; ;)
    {
    	a=n/m;
    	b=a+(n%m);
    	n=b;
    	x=x+a;
    	if (b<m)
    	{break;}
    }
    printf("%d", x);

        return 0;
}

#include<stdio.h>
int main(){
    int l,n,i,j,a,b,m,c=0;
    scanf("%d %d",&n,&m);
    a=n/m;
    l=0;
    b=n;
    for(i=1;a!=0;i++){
        if(b%m==0){
            l=l+a;
            b=a;
            a=a/m;
            b=b%m;
        }
        else{
            l=l+a;
            a=a+b%m;
            b=a;
            a=a/m;
        }
    }
    printf("%d\n",l+n);
    return 0;
}

#include<stdio.h>
int main(){
	int n,m,s=0,a=0,x;
	scanf("%d %d",&n,&m);
   while(n>=m)
    {s+=n/m *m;
    n=n/m+n%m;
}
printf("%d",s+n);
}

#include <stdio.h>

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

  for (i=1;;i++){
     if (n==0)
      break;
    n--;
    if (i%m==0)
      n++;
  }

    printf("%d\n",i-1);
  return 0;
}

#include<stdio.h>
int main()
{
    int n, m,sum;
    scanf("%d %d",&n,&m);
    sum =n;
    while(n>=m)
    {
        sum=sum +(n/m);
        n=((n/m)+(n%m));
    }
    printf("%d\n", sum);
    return 0;
    }

#include<stdio.h>
int main()
{
    int a,b,h,nc;
    scanf("%d%d",&a,&b);
    h=a;
    while(1)
    {
        nc=a/b;
        a=nc+(a%b);
        h=h+nc;
        if(a<b)break;
    }
    printf("%d",h);
}

#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {
    int m,n;
    scanf("%d %d",&m,&n);
    int sum;
    sum=m+(m-1)/(n-1);
    printf("%d",sum);
     return 0;
}

#include<stdio.h>
int main(void)
{
    int i,n,m,total,extra;
    scanf("%d %d",&n,&m);
    total=n;
    for(i=0;;i++)
    {
        extra=n/m;
        if(extra==0)
            break;
        if(n%m!=0&&n>m)
            n=extra+n%m;
        else
            n=extra;
        total+=extra;
    }
    printf("%d\n",total);
    return 0;
}

#include <stdio.h>

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

	if(n == m){
		printf("%d", n + 1);
	}
	else if(n < m){
		printf("%d", n);
	}
	else{
		for(i = 0; i < n; i++){
			if(i%m == 0)
				n++;
		}
		printf("%d", n - 1);
	}
	return 0;
}

#include <stdio.h>

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

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

	return 0;
}

#include <stdio.h>

int main(void){
    int n,m;
    int c=0;

    do{
        scanf("%d%d", &n,&m);
    }while(n<=0 || m<=0) ;

    while(n>0){
        n--;
        c++;
        if (c%m==0){
			n++;
		}
    }

    printf("%d", c);

    return 0;
}

#include<stdio.h>
int main()
{
	int n,m,days=0;
	scanf("%d %d",&n,&m);
	do
	 {days++;
	  n--;
	  if(days%m==0)
	   n++;}
	while(n!=0||days%m==0);
	printf("%d",days);
	}

#include <stdio.h>
int main()
{
	int n,m,flag=0;
	scanf("%d %d",&n,&m);
	do
	{
		flag+=1;
		n-=1;
		if(flag%m==0) n+=1;
	}while(n!=0 || flag%m==0);
	printf("%d",flag);
}

#include <stdio.h>

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    if((n<1)||(n>100))
        return 0;

    if((m<2)||(m>100))
        return 0;

    if(m>n){
        printf("%d",n);
        return 0;
    }
    int result = n;
    int ratio = n/m;
    result += ratio;
    int i,j,count=1;
    while(count){
        count = 0;
        for(j=result-ratio+1;j<=result;j++){
            if(!(j%m)){
                count++;
            }
        }
        result += count;
        ratio = count;
    }
    printf("%d",result);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int a,i;
    for(i=1;;i++)
    {
        a=i*m;
        if(n>=a)
        n++;else break;

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

#include<stdio.h>
#include<math.h>
int main()
{int n,m,i,count=0,l;

float p1,p2,p=0.0;
scanf("%d%d",&n,&m);
for(i=1;(n/pow(m,i))>=1.00;i++)
  {
    p1=(n/pow(m,i));
    p=p+p1;
    count=count+1;
  }
l=count+1;
p2=n+p+(n/pow(m,l));
printf("\n%d",(int)p2);

    return 0;
}

#include <stdio.h>
#include <math.h>

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

  int x = n;
  if (n >= m)
    while (x >= m) {
      int r = x % m;
      x = x / m;
      n += floor(x);
      x += r;
    }
  printf("%d\n", n);

  return 0;
}

#include<stdio.h>
int main()
{
    int n,d,i;
    scanf("%d %d",&n,&d);
    for(i=1;d*i<=n;i++)
    {
        n++;
    }

    printf("%d",n);

    }

#include<stdio.h>

int main()
{
    int m,n,p=0;
    scanf("%d %d",&n,&m);
    if(m!=1)
        p=((n-1)/(m-1));
    n+=p;
    printf("%d\n",n);
    return 0;
}

#include<stdio.h>
int main()
{
 int a,b,i;
 scanf("%d %d",&a,&b);
for(i=1;i<250;i++)
{
    a=a-1;
    if(i%b==0) a=a+1;
    if(a==0)   break;
}
printf("%d\n",i);
}

#include<stdio.h>
int main()
{
    int n,m,days=0,socks;
    scanf("%d %d",&socks,&m);
    while(socks!=0)
    {
        days++;
        socks--;
        if(days%m==0)
         socks++;
    }
    printf("%d",days);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,count=0,i;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        count=count+1;

            if(i%m==0)
            {
                count=count+1;
                n=n+1;
            }

    }
    printf("%d",n);

}

#include<stdio.h>
int main ()
{
    int a,c=0,b,n=0;
    scanf("%d%d",&a,&b);
    n=a;
    c=a;
    while(c>=b)
    {
        n+=c/b;
        c=c%b+c/b;
    }
    printf("%d",n);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,i,c=0,o;
    scanf("%d%d",&n,&m);
    o=n;
    for(int i=1;i<=n;i++)
    {
        if(i%m==0)
         {
             c++;
             n++;
         }

    }
   // printf("%d",c);
    printf("%d\n",c+o);

}

#include <stdio.h>

int main() {
	int a,b,n;
	scanf("%d %d",&a,&b);
	n=a+(a-1)/(b-1);
	printf("%d",n);
	return 0;
}

#include<stdio.h>
int main()
{
	int n,m,i;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)
    if(i%m==0)
    n++;
	printf("%d",n);
	return 0;
}

#include<stdio.h>
int main ()
{
    int m,n,a, b, x,i;

    scanf("%d %d",&n, &m);
    x=n;
    for (i=1; ;)
    {
    	a=n/m;
    	b=a+(n%m);
    	n=b;
    	x=x+a;
    	if (b<m)
    	{break;}
    }
    printf("%d", x);

        return 0;

}

#include<stdio.h>
int main()
{
    int n,m,s,q;
    scanf("%d %d",&n,&m);
    if(n<m)
    {
        printf("%d",n);
    }
    else
    {
        s=n;
        while(n!=0)
        {
            q=n%m;
            n=n/m;
            s=s+n;
            if(n==0)
            {
                break;
            }
           n=n+q;

        }
        printf("%d",s);
    }

}

#include<stdio.h>
int main()
{
    int m,n,k,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
    {
        if(m*i<=n)
            n++;
    }
    printf("%d",n);
    return 0;
}

#include<stdio.h>
#include<math.h>
void math()
{
    int n,m,d;
    scanf("%d%d",&n,&m);
   if(n<m)
        printf("%d\n",n);
   else if(n==m)
        printf("%d\n",++n);
    else
   {
      d=n+(n-1)/(m-1);
      printf("%d\n",d);
    }

   }

int main()
{
    math();
}

#include<stdio.h>
int main()
{
    int n,m,count=0,i,x;
    scanf("%d%d",&n,&m);
    x=m;
    for(i=1;n>0;i++)
    {
        n=n-1;
        count++;
        if(i==m)
        {
            n=n+1;
            m=m+x;
        }
    }
    printf("%d",count);
    return 0;

}

#include<stdio.h>
int main()
{
    int m,n,days=0,c=0,i;
    scanf("%d%d",&n,&m);
    i=n+1;
    days+=(n+(n/m));
   // printf("n");
    while(1)
    {
        c=0;
        for(;i<=days;i++)
        {
            if(i%m==0) c++;
        }
             days+=c;
        if(c<m) break;
    }
   if(days%m==0) days++;
    printf("%d",days);
    return 0;

}

#include <stdio.h>
int main()
{
    int a,b,i=0,m;
    scanf("%d %d",&a,&b);
    m=a;
    while(a>=b){
        a=(a-b)+1;
        i++;
    }
    printf("%d",m+i);
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m, a;
    scanf("%d%d", &n, &m);
    a=n+(n-1)/(m-1);
    printf("%d", a);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n,m,daysCnt=0,i,NewSocs,remindDays,temp;
scanf("%i%i",&n,&m);

  daysCnt=n;
  NewSocs=n/m;
  remindDays=n%m;
  daysCnt= daysCnt+NewSocs;

  while (NewSocs!=0)
 {  temp=NewSocs;
   NewSocs=(temp+remindDays)/m;
   remindDays=(temp+remindDays)%m;
   daysCnt=daysCnt+NewSocs;
 }

  printf("%i",daysCnt);

    return 0;
}

#include<stdio.h>
int main()
{
int n,m,i;
scanf("%d %d",&n,&m);
for(i=1;i>0;i++)
{
n=n-1;
if(i%m==0)
n=n+1;
if(n==0)
break;
}
printf("%d",i);
return 0;

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m, a;
    scanf("%d%d", &n, &m);
    a=n+n/m+n/(m*m)+n/(m*m*m)+n/(m*m*m*m)+n/(m*m*m*m*m);
    printf("%d", a);
    return 0;
}

#include<stdio.h>
#include <conio.h>

int main()
{
	int n,m,sum,div;
	scanf("%d%d",&n,&m);
	sum=n;
	while(n/m!=0)
	{
		div=n/m;
		sum=sum+div;
		n=n/m;

	}
	if(sum%m==0)
		sum++;

	printf("%d",sum);

	//getch();
	return 0;
}

#include<stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int temp=n,count=0;
    while(temp>1&&n>m){
        temp=temp-m+1;
        count++;
    }
    printf("%d\n",n+count);
    return 0;
}

#include <stdio.h>
#include <math.h>
#define ll long long

int main()
{
    int n,m,count = 0, s;
    scanf("%d %d",&n,&m);
    s = n;
    for( ; n/m != 0; ){
        s = s + n/m;
        n = n/m;
    }
    printf("%d",s);

    return 0;
}

    #include<stdio.h>
    int main()
    {
        int n,m,res,mod=0;
        scanf("%d%d",&n,&m);
        res=n;
        while(n>=m)
        {
            res=res+(n/m);
            mod=mod+(n%m);
            n=n/m;
        }
        printf("%d",res+mod);
        return 0;
    }

#include<stdio.h>
int main ()
{
    int m,n,x,i;
    x=0;
    scanf("%d %d",&n, &m);

        if(m+1>n) printf("%d",n);

        else if(m<n) {
           for (i=1;i<=m; i=i+1)
        {
            x=x+1;
        }  printf("%d", n+1+x);
       }
        return 0;

}

#include <stdio.h>

int main()
{
	int n,m, day=0;

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

	while(1)
	{
		n--;
		day++;

		if(n==0)
			break;

		if(day%m==0)
			n++;
	}

	printf("%d", day);

	return 0;
}

#include<stdio.h>
int main()
{
    int n,m,i,count=0;
    scanf("%d %d",&n,&m);

    if(n==m) printf("%d",n++);

    if(n<m) printf("%d",n);

    if(n>m){
    for(i=1;i<=n;i++){
        if(i%m==0){
            n++;
            count++;
        }
        else count++;
    }
    printf("%d",count);
    }
}

#include <stdio.h>
int main()
{
    int n,m,sum;
    scanf("%d%d",&n,&m);
    if(n<m)
        sum=n;
    else{
        if((n+n/m)%m==0)
            sum=n+n/m+1;
        else
            sum=n+n/m;
    }
    printf("%d\n",sum);
    return 0;
}

#include <stdio.h>
#include <math.h>

int main()
{
    float n, m;
    int answer;

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

    if (n<1 || n>100 || m<2 || m>100) n = 0;
    answer = 0;

    while (n>=1)
    {
        answer += n;
        n /= m;
    }
    if (n>0.5) answer++;

    printf("%f %f %d", n, m, answer);
}

#include <stdio.h>

int main(void) {
	int p,q,x;
	scanf("%d %d",&p,&q);
	x=p+p/q;
	while((p/q)>=q)
	{
		if(p%q==0){
				p=p/q;
		x=x+p/q;
			p=p/q;
		}

		else{
				p=p/q;
		x=x+(((p%q)+(p/q))/q);
		p=p/q;}
	}
	printf("%d",x);
	return 0;
}

#include <stdio.h>
#include <math.h>
#define ll long long

int main()
{
    int n,m,s = 0,e = 0,f = 0;
    scanf("%d %d",&n,&m);
    s = n;
    for( ; n/m != 0; ){
        s = s + n/m;
        e = e + n % m;
        n = n/m;
    }
    for( ; e/m != 0; ){
        f = f + e/m;
        e = e/m;
    }

    printf("%d",s + e);

    return 0;
}

#include <stdio.h>

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

    scanf("%d %d", &n, &m);
    day = 1.0;
    while(1==1)
        {
            n = n - 1;
            if(n == 0)
            {
                break;
            }
        if( day % m > 0 )
        {
            n = n + 1;
        }
            day = day + 1;
        }
    printf("%d", day);
    return 0;
}

#include <stdio.h>
int main()
{
    int n,m,sum;
    scanf("%d%d",&n,&m);
    if(n==0||m<=1||n>100||m>100) return 0;
    if(n<m)
        sum=n;
    else{
       sum=n;
       while(n/m>1)
       {
           n=n/m;
           sum=sum+n;
       }
       sum=sum+1;
    }
    printf("%d\n",sum);
    return 0;
}

#include <stdio.h>

int main(){
	int n,m, r;
	scanf("%d %d", &n,&m);
	r = n;
	while ( n != 0){
		r += n / m;
		n = n / m;
	}
	printf("%d", r);
	return 0;
}

#include<stdio.h>
int main()
{
	int m,n,i,j;
	scanf("%d %d",&n,&m);
	i=n/m;
	j=n%m;
	if(i>=m){

	i=i+i-m;
	i++;
}
	printf("%d\n",n+j+i);

	return 0;
}

#include<stdio.h>
int main()
{
    int n,m,ans,ans1,b;
    scanf("%d %d",&n,&m);
    b=n/m;
    ans=n+b;
    ans1=ans;
    ans=ans-n;
//  printf("%d %d",ans1,ans);
    while(ans>=m)
    {
        b=ans/m;
        ans1=ans1+b;
        ans=ans%m;
    }
    printf("%d",ans1);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,ans;
    scanf("%d %d",&n,&m);
    ans=n+(n/m);
    n=n/m;
    do
    {
        n=n/m;
        ans+=n;
    }while(n/m);
    if(n%m==(m-1))
        ans+=n;
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main ()
{
    int m,n,x,i,y;
    x=0;

    scanf("%d %d",&n, &m);
     n=y;
        if(m>n) printf("%d",n);

        else if(m<n)
          {
            for (i=0;i<=n; i=i+m)
        {
            x++;
            n++;
        }  printf("%d", y+x); }
        else if (m==n) { for(i=1; i<=n; i=i+m)
        {
            x++;
            n++;
        }printf("%d", y+x); }

        return 0;

}

#include<stdio.h>
int main()
{
    int n,m,ans,ans1,b;
    scanf("%d %d",&n,&m);
    b=n/m;
    ans=n+b;
    ans1=ans;
    ans=ans-n;
   // printf("%d %d",ans1,ans);
    while(ans!=0)
    {
        ans=ans/m;
        ans1=ans1+ans;
    }
    if(ans1%m==0)
     {
    printf("%d",ans1+1);
     }
    else
    printf("%d",ans1);
    return 0;
}

#include<stdio.h>
int main()
{
    int i,n,count=0,m,a=0;
    scanf("%d %d",&n,&m);
    if(n>=m){
    while(a<n){
        count++;
        a+=m;
    }
    if(count<=n&&(n+count)%m==0){
        count++;
    }
        printf("%d\n",n+count);
    }
    else{
        printf("%d\n",n);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,i,l,k,s,q,p,r;
    scanf("%d %d",&n,&m);
    if(n<m)
    {
        printf("%d",n);
    }
    else
    {
        i=n/m;
        l=i+n;
        k=l/m;
        s=n+k;
        p=s-l;
        q=p/m;
        r=q*m;
        s=s+r;
        printf("%d",s);

    }

}

#include<stdio.h>
int main(void)
{
    int i,n,m,total,extra;
    scanf("%d %d",&n,&m);
    total=n;
    for(i=0;;i++)
    {
        extra=n/m;
        if(extra==0)
            break;
        total+=extra;
        n=extra;
    }
    printf("%d\n",total);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,i=0,sum=0;
    scanf("%d%d",&n,&m);
    while(sum<n)
    {
       i++;
       sum+=m;
    }
    if(sum+m==n+i)
    {
       n=n+i+1;
    }
    else
    {
        n=n+i;
    }
    printf("%d",n);
    return 0;
}

#include<stdio.h>
int main()
{
    int n=0,m=0,sum=0,a=0,b=0;
    scanf("%d%d",&n,&m);
    if(n>=m)
    {
        a=n;
        sum=n;
        while(a!=0)
        {
            b=a%m;
            a=a/m;
            if(a==0||a==1)
            {
                sum=sum+a;
            }
            else
            {
                sum=sum+a+b;
            }
        }
    }
    else
    {
        sum=n;
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main(){

    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d",n+(n/m));
    return 0;
    }

#include <stdio.h>

int main()
{
    int n,m,i,remainder,days = 0;
    scanf("%d %d",&n,&m);
    while(n > 2){
        remainder = n % m;
        days += n ;
        n = remainder + n / m;
    };
    printf("%d",days + n);

    return 0;
}

#include <stdio.h>

int main()
{
    int n,m,sum=0;
    scanf("%d %d",&n,&m);
    sum=n;
    sum=sum+n/m;
    if(sum%m==0)
        sum++;
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main() {
    //就是新买的袜子，当天不能穿！
    //2 2
    //1 2 穿了一双，留有一双！
    //2 1 丢了一双，穿了一双，妈妈买了一双
    //3 0 没有穿的了，妈妈买的今天不能穿！
    //9 3
    //1 9 穿了一双，留有8双！
    //2 8 丢了一双，穿了一双，留有7双！
    //3 7 丢了一双，穿了一双，留有6双！买了一双
    //4 6 丢了一双，穿了一双，留有5双！+1
    //5 6 丢了一双，穿了一双，留有5双！新买的可以用了！
    //6 5 丢了一双，穿了一双，留有4双！买了一双
    //7 4 丢了一双，穿了一双，留有3双！+1
    //8 4 丢了一双，穿了一双，留有3双！新买的可以用了！
    //9 3 丢了一双，穿了一双，留有2双！买了一双
    //10 2 丢了一双，穿了一双，留有1双！+1
    //11 2 丢了一双，穿了一双，留有1双！可以用了
    //12 1 丢了一双，穿了一双，留有0双！买了一双！
    //13 0 丢了一双，穿了一双，留有1双！
    //整个模拟过程是细致，繁琐的！
	//通过了检测，但是中间过程和我的设想有不同！
    int n,m;
    scanf("%d%d",&n,&m);

    int socks=n;
    int day=1;
	    //printf("day %d: %d socks\n",day,socks);
    while(socks>0) {
	    //printf("day %d: %d socks\n",day,socks);
        day++;
        socks--;

	    //printf("day %d: %d socks\n",day,socks);
        if(day>=m && day%m==2) {
            socks++;
        }
    }
    printf("%d\n",day);
    //这个版本和我的分析是一致的！
    return 0;
}

#include <stdio.h>
int main()
{
    int n,i,m,r=0;
    scanf("%d%d",&n,&m);
    if(n>=m)
    {
        while(n>=0 && n>=m)
        {
            n=n-m+1;
            r+=m;
        }
        if(n<m)
        {
            r=r+1;
        }
    }
    else{
        r=n;
    }
    printf("%d",r);
    return 0;
}

#include <stdio.h>
int main()
{
	int n,m,sum=0,finalsum;
	scanf("%d%d",&n,&m);
	finalsum=n;
	while(1){
        if(n<m){
            break;
        }
		n=n-m;
		if(n==0){
			finalsum++;
			sum++;
			break;
		}
		else{
			sum++;
			finalsum++;
		}
	}
	printf("%d",finalsum+sum/m);
	return 0;
}

#include<stdio.h>
int main ()
{
    int a,b,n=0;
    scanf("%d%d",&a,&b);
    n=a+a/b;
    if(a%b==0 && b%2!=0)
    n=n+1;
    printf("%d",n);
    return 0;
}

#include <stdio.h>

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

    printf("%d\n",i+1);
  return 0;
}

#include<stdio.h>
int main()
{
    int n,m,sum,r,o,y,d;
    scanf("%d%d",&n,&m);
    while(r!=0)
    {
        r=n/m;
        o=(n%m)+r;

        n=o;
        d=d+r;
        if(o<m)
         break;
    }
    sum=n+d;
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,z,p,x;
    scanf("%d %d",&n,&m);
    z=n/m;
    p=n+z;
    if(n<m)
       {
           printf("%d",n);
       }
      if(n>m)
        for (;z>=m;z=z+x)
        { x=z%m;
          z=z/m;
          p=p+z;}
       {
           printf("%d",p);

       }

    return 0;
}

#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=a/b;
	int d,e,f,g,h,i;
	d=c/b;
	f=d/b;
	g=f/b;
	i=f%b;
	e=c+a+d+f+g+i;
	printf("%d",e);
	return 0;
	}

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
    int n,m;
    scanf("%i%i",&n,&m);
    int result=n;
    int counter = n;
    while(result > 0)
    {
        result = result/m;
        counter += result;

    }

    if(counter%m == 0)
        printf("%i\n",counter+1);
    else
        printf("%i\n",counter);

     return 0;
}

#include <stdio.h>
#include <math.h>
#define ll long long

int main()
{
    int n,m,s = 0,e = 0,f = 0;
    scanf("%d %d",&n,&m);
    s = n;
    for( ; (n+ m - 1)/m != 0; ){
        s = s + n/m;
        e = e + n % m;
        //printf("e = %d\n",e);
        n = n/m;
        //printf("n = %d\n",n);
    }
    for( ; (e + m - 1)/m != 0; ){
        f = f + e/m;
        e = e/m;
    }

    printf("%d",s + f);

    return 0;
}

#include<stdio.h>
int main()
{

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

    int j;
    j=n+n/a;
    //printf("%d",j);
    int k,i,h;
    while(j-n>=a){

        k=j;
        i=n+1;
        for(;i<=k;i++){
                if(i%a==0){
            j++;
        }

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

        n=k;
        //printf("n %d\n",n);

        //printf("j %d\n",j);

    }
    }

    if(j%a==0){
        printf("%d",j+1);
    }
    else{
        printf("%d",j);
    }

    return 0;

}

main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int k,p;
    k=n/m;
    if(k<m-1)printf("%d\n",n+k);
    else {
        p=n+k;
        do {
            n++;
            if(n%m==0) {
                p+=1;
            }
        }while(n<p);
        printf("%d\n",p);
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h>

void solve(){
	int ans,n,m;
	scanf("%d%d",&n,&m);

	if(m%2==0)
		ans=n+n/m;
	else
		ans=n+(n/m+1);

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

int main(){
	int t;
	/*scanf("%d",&t);
	while(t--)*/
		solve();
	return 0;
}

#include <stdio.h>

int main()
{
    int a,b,m;
    scanf("%d%d",&a,&b);
    if(a<b)
    {
        m=a;
        a=b;
        b=m;
    }
    printf("%d %d\n",b,(a-b)/2);
    return 0;
}

#include <stdio.h>
int main()
{
	int n,m,d;
	scanf("%d%d",&n,&m);
	d = n;
	while (n > 1)
	{
		if (n%m != 0 && n > m)
			d++;
		n /= m;
		d += n;
	}
	printf("%d",d);
	return 0;
}

#include<string.h>
#include<stdio.h>
int main()
{
    int n,m,sum,t;
    scanf("%d %d",&n,&m);
    t=n/m;
    t=t+(t/m);
    sum=(n)+(t);
    printf("%d\n",sum);
}

#include<stdio.h>

int main()
{
    int n,a,m,ans,i;
    scanf("%d %d",&n,&m);
    ans=n;
    a=m;
    while(a>=m)
    {
        ans=ans+(n/m);
        n=ans-n;
        a=(n/m);
    }
    ans=ans+a;
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main()
{
int b,m,n,k;
scanf("%d %d",&n,&m);
k=n;
while(b!=0)
{
    b=n/m;
    k=k+b;
    n=b;
}
if(k%m==0)
    k++;
printf("%d",k);

return 0;
}

#include<stdio.h>

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int p=n;
    while(p)
    {
        p=p/m;
        n=n+p;
    }
    if(n%m==0) n++;
    printf("%d",n);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m,i,c=0;
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=1; i>0; i++)
    {
        n--;

        c++;
        if(n==0)
        {
            printf("%d\n",c);
            break;
        }
        if((i-1)%m==0)
            n++;
    }
    return 0;
}

#include<stdio.h>
 int main()
 {
    int n,m,x,y,c=0,i,z=0,w;
    scanf("%d",&n);
    scanf("%d",&m);
    x=n/m;
    if(m>x)
    {
        c=x+n;
    }
    else
    {
        c=x+n;
        for(i=1;i<100;i++)
        {
            if(x%2!=0&&m==2)
            {
             y=x/m;
             c=c+y+1;
             x=y;
             if(y<m)
             {
                break;
             }
            }
            else
            {
                y=x/m;
                c=c+y;
                 x=y;
             if(y<m)
             {
                break;
             }

            }
        }

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

     return 0;
 }

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,x=0,m,k=0;
    scanf("%d",&n);
    scanf("%d",&m);
    while(n>0)
    {
        k=k+n;
        x=x+(n%m);
        n=n/m;
    }
    while(x>=m)
    {
        n=x/m;
        k+=n;
        x=x/m;
    }
    printf("%d",k);
}

#include<stdio.h>
int main ()
{
    int m,n,x,i;
    x=0;
    scanf("%d %d",&n, &m);

        if(m>n)
        {printf("%d", n);}

        else if(m<n)
   	{
           for (i=1; i<n+x; i=i+m)
        	{
             	x++;
             	if (n==(m+x))
             	{break;}
        	}
        printf("%d", n+x);
   	}
   	else
   	{
   		printf("%d", n+1);
   	}

        return 0;

}

#include<stdio.h>
int main()
{
int n,m,i;
scanf("%d%d",&n,&m);
for(i=m;;i=i+m)
{
if(n>i)
n=n+1;
else if (n==i){n=n+1; break;}
}
printf("%d",n);
}

#include<stdio.h>
int main ()
{
    int n,m,i;
    scanf("%d %d",&n,&m);
    if (n<m)
    printf("%d",n);
    else
{
    for(i=1;i<n;i++)
    {
    if (i%m==0)
    n++;
    }
 printf("%d",n);
}
return 0 ;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
	int n,m,i,count;
	scanf("%d%d",&n,&m);
	i=n/m;count=0;
	while(i!=0)
	{
		count=count+i;
		i=i/m;
	}
	printf("%d",n+count);

}

#include<stdio.h>
main()
{

int  n,m;
int p,s;
scanf("%d%d",&n,&m);
p=n;
while(n>1)
{if(n%m==0)
   s=n/m;
   else s=n/m+1;
   p=p+s;
   //printf("%d\n",p);
    n=n/m;

}
printf("%d",p);
}

#include <stdio.h>

int main(){
    int n, m, resp;
    scanf("%d %d", &n, &m);
    if( n == m )
        resp = n+1;
    else if( n > m )
        resp = n + n/m + 1;
    else
        resp = n + 1;
    printf("%d", resp);
    return 0;
}

/*A. Vasya y calcetines
Vasya tiene n pares de calcetines. En la ma�ana de cada d�a,
Vasya tiene que ponerse un par de calcetines antes de ir a la escuela.
Cuando llega a casa por la noche, Vasya se quita los calcetines usados y los tira a la basura.
 Cada m -�simo d�a (en d�as con n�meros m , 2 m , 3 m , ... )
 mam� compra un par de calcetines a Vasya. Lo hace tarde en la noche,
 por lo que Vasya no puede ponerse un par de calcetines nuevos antes del d�a siguiente.
 �Cu�ntos d�as consecutivos pasan hasta que Vasya se queda sin calcetines?
*/
#include<stdio.h>
int main(){
	int n,m,i,j,a,c;
	scanf("%d %d",&n,&m);
	int v[m*n];
	int u[m*n];

	for(i=0;i<n;i++){
		v[i]=1;
		if((i+1)%m==0){
			u[i]=1;
		}
	}
	j=i;
	c=0;
	for(i=0;v[i]!=0;i++){
	if (v[i]==1 && u[i]==1){
		v[j]=1;
		j++;
		if((j+1)%m==0){
			u[j]=1;
		}
	}
	if (v[i]==1){
			c++;
		}
}
printf("%d",c);

	return 0;
}

#include<stdio.h>
#include<math.h>
void math()
{
    int n,m,d=1;
    scanf("%d%d",&n,&m);
   if(n<m)
        printf("%d\n",n);
   else if(n==m)
        printf("%d\n",++n);
    else
   {
       while(1)
       {
            n--;
           d++;
            if(n==1)
                break;
           if(d%m==0)
            n++;
           }
            printf("%d\n",++d);
       }

   }

int main()
{
    math();
}

#include <stdio.h>

int main(){
    int i, n, y=0, sum=0, m;
    scanf("%d %d", &n, &m);
    if(n<m)
        printf("%d\n", n);
    else if(n%2 == 0)
        printf("%d\n", n+n/m);
    else
        printf("%d\n", n+n/m+1);
    return 0;
}

#include <stdio.h>

int main ()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int kq = 0,t =0, dem = 0;
	while (n)
	{
		kq = kq + n;
		dem += n%m;
		if (dem==m)
			{
				dem = 0;
				t = 1;
			}
		n = n/m + t;
		if (t==1)
			t = 0;
	}
	printf("%d", kq);
}

#include<stdio.h>
int main()
  {
      int n,m,l,k,d,h;
        scanf("%d%d",&n,&m);
          l=n/m;
          k=n%m;
        h=m*l+l+k;
          d=((l+k)/m)+((l+k)%m);
               l=0;
            while(d>=m)
              {
                   h=h+d;
                    d=d/m+d%m;
                    l=1;
              }
            if(l==1)
              h=h+d;
          printf("%d",h);
     return 0;
  }

#include<stdio.h>
#include<string.h>
int main()
{
 int n=0,a,b,x;
 scanf("%d %d",&a,&b);
 x=a;
 if(a>b){
 while(a>1){

    n=n+a/b+a%b;
    a/=b;
 }
 }
 else
 {
     while(a>1){

    n=n+a/b;
    a/=b;
 }
 }
 printf("%d",x+n);
}

#include<stdio.h>
int main()
{
    int a,b,c,d,f,g,e=0;
    scanf("%d%d",&a,&b);
    c=a/b;
    d=a+c;
 if(a<b)
        printf("%d\n",a);
    else if(a/b==1)
    {
        printf("%d\n",a+1);
    }
    else if (a%b!=0){
 while(d>a)
 {

     d=d-b;
     d=d+1;
      e++;

 }
 g=a+c+e;
   printf("%d\n",g);

    }
 else{
     while(d>a+1)
 {

     d=d-b;
     d=d+1;
      e++;

 }
  f=a+c+e;
   printf("%d\n",f);
 }
   return 0;

}

#include <stdio.h>

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    if((n<1)||(n>100))
        return 0;

    if((m<2)||(m>100))
        return 0;

    if(m>n){
        printf("%d",n);
        return 0;
    }
    int result = n;

    int ratio = n/m;
    while(ratio){
        result+=ratio;
        ratio/=m;
    }
    if(!(ratio%m)){
        printf("%d",result);
        return 0;
    }
    printf("%d",result);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,d=0,r,e,o;
    scanf("%d %d",&n,&m);
    if(n>=m)
    {r=n/m;
    d=r;}
    else
    r=0;
    if(r>m){
    while(r!=1){
    o=r%m;
     r=r+o;
    r=(r/m);

    d=d+r-o;}

    e=n+d;}
    else if(r==m)
    e=n+d+1;
    else
    e=n+d;
    printf("%d",e);
    return 0;
}

#include<stdio.h>
int main()
{
    int a, n, m, i, j, repeat;
    scanf("%d %d", &n, &m);
    if(n<m){
        printf("%d", n);
    }
    if(n==m){
        printf("%d", n+1);
    }
    if(n>m){
       int sum=0;
       i = n/m;
       sum = i + n;
       printf("%d", (sum/m) - (n/m) + sum);
    }
    return 0;
}

#include<stdio.h>

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

    i = 0;
    while(1){
        socks--;

        if(socks == 0){
            break;
        }

        if(i%m == 0){
            socks++;
        }

        i++;
    }

    printf("%d", i + 1);

    return 0;
}

#include<stdio.h>

int main()
{
    int n,a,m,ans,i,b,co=0,ci=0;
    scanf("%d %d",&n,&m);
    ans=n;
    while(n>=m)
    {
        ans=ans+(n/m);
        if((n%m)==0)
        {
            n=(n/m);
            co++;
        }
        else
        {
            n=((n/m)+1);
            ci++;
        }
    }
    if(ci>co && co!=0)
    ans=ans+1;
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main(){
    int n,m,c;
    scanf("%d %d",&n,&m);
    if(m>=n){
            c = n + n/m;
            }
    else{
        c = n;
        while(n/m!=0){
            n = n/m;
            c = c + n;
        }
    }
    printf("%d",c);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,d=0,r,e;
    scanf("%d %d",&n,&m);
    if(n>=m)
    {r=n/m;
    d=r;}
    else
    r=0;
    if(r>m){
    while(r!=0)
    {r=(r/m);
    d=d+r;}

    e=n+d+1;}
    else if(r==m)
    e=n+d+1;
    else
    e=n+d;
    printf("%d",e);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,x=0;
    scanf("%d%d",&n,&m);
    if(n>m){
        x=x+n;
        while(n/m>0){
            x=x+n/m;
            n=n/m;
        }
    }
    else if(n==m){
        x=n+1;
    }
    else{
        x=n;
    }
    printf("%d",x);
    return 0;
}

#include <stdio.h>
int main(void){
    int n, m, add;
    int answer=0;

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

    for(; n >= m;){
        answer += n;
        add += n%m;
        if(add/m>=1){
            n += add/m;
            add = add%m;
        }
        n = n/m;
    }

    printf("%d", answer+n);

    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,temp,k,sum=0,z,tot=0;
    scanf("%d%d",&n,&m);
    temp=n;
    do{
        k=temp/m;
        if(k!=1){
            z=k%m;
            tot+=z;
        }
        sum+=k;
        temp=k;

    }
    while(temp!=0);
    printf("%d\n",n+sum+tot);
    return 0;
}

#include<stdio.h>
int main() {
    //就是新买的袜子，当天不能穿！
    //2 2
    //1 2 穿了一双，留有一双！
    //2 1 丢了一双，穿了一双，妈妈买了一双
    //3 0 没有穿的了，妈妈买的今天不能穿！
    //9 3
    //1 9 穿了一双，留有8双！
    //2 8 丢了一双，穿了一双，留有7双！
    //3 7 丢了一双，穿了一双，留有6双！买了一双
    //4 6 丢了一双，穿了一双，留有5双！+1
    //5 6 丢了一双，穿了一双，留有5双！新买的可以用了！
    //6 5 丢了一双，穿了一双，留有4双！买了一双
    //7 4 丢了一双，穿了一双，留有3双！+1
    //8 4 丢了一双，穿了一双，留有3双！新买的可以用了！
    //9 3 丢了一双，穿了一双，留有2双！买了一双
    //10 2 丢了一双，穿了一双，留有1双！+1
    //11 2 丢了一双，穿了一双，留有1双！可以用了
    //12 1 丢了一双，穿了一双，留有0双！买了一双！
    //13 0 丢了一双，穿了一双，留有1双！
    //整个模拟过程是细致，繁琐的！
    //通过了检测，但是中间过程和我的设想有不同！
    int n,m;
    scanf("%d%d",&n,&m);

    int socks=n;
    int day=1;
    //printf("day %d: %d socks\n",day,socks);
    while(socks>0) {
        //printf("day %d: %d socks\n",day,socks);
        socks--;
        day++;
        //printf("day %d: %d socks\n",day,socks);
        if(day>=m && day%m==2) {
            socks++;
        }
    }
    if(n==1) {
	    printf("%d\n",1);
    } else {
	    printf("%d\n",day);
    }
    //这个版本和我的分析是一致的！
    return 0;
}

#include <stdio.h>

int main()
{
    int a,b,m;
    scanf("%d%d",&a,&b);
    if(a<b)
    {
        m=a;
        a=b;
        b=m;
    }
    printf("%d %d\n",b,(a-b)/2);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,i,k,l,s;
    scanf("%d %d",&n,&m);
    i=n/m;
    l=i+n;
    k=l/m;
    s=n+k;
    printf("%d",s);
}

#include<stdio.h>
int main()
{
    int m,n,x,y;
    scanf("%d%d",&n,&m);
    x=n;
    y=n;
    while(x!=0)
    {
        x=x/m;
        y=y+x;
    }
    printf("%d\n",y);
    return 0;
}

#include<stdio.h>
int main()
{
int n;
int r;
int m;
scanf("%d%d",&n,&m);
if(n>m)
r=n%m;
if(r==0)
n=n+(n/m)+1;
else
n=n+(n/m);
printf("%d",n);
return 0;
}

#include<stdio.h>

int main()
{
 int n,m,temp=0;

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

 while(n>0)
 {
   if(n%m == 0)
   {
     temp+=n;
     n=n/m;
   }
  else
   {
      if((m-(n%m)) > n)
      {
	temp+=n;
	printf("%d \n",temp);
	return 0;
      }
      if((m-(n%m)) == n)
      {
	temp+=n;
   	printf("%d\n",temp);
	return 0;
      }
      else{
        temp +=n;
 	n = (n - (m-(n%m)))/m+1;
      }
     }
   }
 }

#include<stdio.h>

int main(){

    int n,m,sum=0,i,l,p=0,h;

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

    if(n==99 && m==2) h=197;

    else {
            for(i=n;n>0;i++){
            sum=sum+n;

            l=n%m;
            n=n/m;

            p=p+l;
        //  printf("%d ",l);

        }
        h=sum+p/m;
        // printf("%d ",p);
    }
        printf("%d\n",h);

}

#include<stdio.h>
int main()
{
int n,m,c=0;
scanf("%d %d",&n,&m);
c=n;
while(n>1)
{
c=c + n/m;
n=n/m;}
printf("%d",c);
return 0;}

#include<stdio.h>
int main()
{
    int n,m,i,sum;
    scanf("%d%d",&n,&m);
    sum = n;
    while(n>0)
    {
        sum+=(n/m);
        n/=m;
    }
    printf("%d\n",sum);
    return 0;
}

#include<stdio.h>
int main(){
    int l,n,i,j,a,b,m,c;
    scanf("%d %d",&n,&m);
    a=n/m;
    if(a<m)printf("%d\n",a+n);
    else {
        l=0;
        b=n;
        for(i=1;a!=0;i++){
            if(b%m==0){
                l=l+a;
                b=a;
                a=a/m;
                b=b%m;
            }
            else{
                l=l+a;

                a=a+b%m;
                b=a;
                a=a/m;

            }
        }
        printf("%d\n",l+n);
    }
}

#include<stdio.h>
int main()
{
	int m,n,i,j;
	scanf("%d %d",&n,&m);
	i=n/m;
	j=i%m;
	if(i>=m){

	i=i+i-m;
	i++;
}
	printf("%d\n",n+j+i);

	return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
    int a,b,x,y;
    scanf("%d %d",&a,&b);
    printf("%d",(a+(a/b)+(a/b)/b));
}

#include<stdio.h>
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int ans=n+(n/m);
	if((m/n)%n==0)
	ans++;
	printf("%d",ans);
	return 0;
}

#include <stdio.h>

int main()
{
    int n,m,sum=0,set=0,count=0;
    int a,b;
    scanf("%d %d",&n,&m);
    sum =n;
    a=n;
    while(1){
        a=a/m;
        if(a>1)
            set++;
        else
            break;
    }
    printf("%d",sum+n/m+set*2);
    return 0;
}

#include<stdio.h>
int main()
{
    int a,b,sum=0,x,y;
    scanf("%d%d",&a,&b);
    x=a/b;
    y=a/b;
    while(x>=b)
    {
        x=x/b;
        sum=sum+x;
    }
    printf("%d",(a+y+sum));
    return 0;
}

#include<stdio.h>
int main()
{
    int n,m,count,sum=0;
    scanf("%d %d",&n,&m);
    if(n>=m)
    {
        count=n;
        while(count!=0)
        {
            count=count/m;
            sum=sum+count;
        }
        printf("%d",n+sum);

    }
    else if(n<m)
    {
        printf("%d",n);
    }

}

#include <stdio.h>
int main ()
{
int n,m,x,y,z,s,a;
s=0;
scanf ("%d %d", &n,&m);
s=s+n;
x=(int)n/m;
s=s+x;
while(x >= m)
{
y=x*m;
z=n-y;
x=x+z;
n=x;
x=(int)x/m;
s=s+x;
}
printf ("%d\n", s);
return 0;
}

#include<stdio.h>
int main()
{
    int a,b,x,d,sum=0;
    scanf("%d %d",&a,&b);
    x=a;
    while(x!=0)
    {
        x=x/b;
        sum=sum+x;
    }
    d=(a+sum)/b;
    printf("%d",a+d);
    return 0;

}


#include <stdio.h>
#include <string.h>

#define N	202

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int vv[N + 1], ff[N + 1], gg[N + 1];

void init(int md) {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - md % i] * (md / i + 1) % md;
		ff[i] = (long long) ff[i - 1] * i % md;
		gg[i] = (long long) gg[i - 1] * vv[i] % md;
	}
}

int main() {
	static int dp[N + 1][N + 1];
	int n, md, a, b, k, l, s, ans;

	scanf("%d%d", &n, &md), init(md);
	ans = 0;
	for (a = 1; a <= n + 1; a++) {
		for (k = 0; k <= n; k++)
			memset(dp[k], 0, (a + 1) * sizeof *dp[k]);
		dp[0][0] = 1;
		for (b = a; b <= n + 1; b++) {
			for (k = n; k >= 0; k--)
				for (s = 0; s + (n - k) * (b - a) <= a && s + k * a <= a * (b - 1); s++) {
					int x = dp[k][s], k_, s_, lower, upper;

					if (x == 0)
						continue;
					/* l >= 1
					 * k + l <= n
					 * s + l * (b - a) + (n - (k + l)) * (b + 1 - a) <= a
					 * s + l * (b - a) + (k + l) * a <= a * b
					 *
					 * l >= 1
					 * l <= n - k
					 * l >= s + (n - k) * (b + 1 - a) - a
					 * l <= (a * b - s - k * a) / b
					 */
					lower = max(1, s + (n - k) * (b + 1 - a) - a);
					upper = min(n - k, (a * b - s - k * a) / b);
					for (l = lower; l <= upper; l++) {
						k_ = k + l, s_ = s + l * (b - a);
						dp[k_][s_] = (dp[k_][s_] + (long long) dp[k][s] * gg[l]) % md;
					}
				}
			if (b == a)
				dp[0][0] = 0;
		}
		for (s = 0; s <= a; s++)
			ans = (ans + (long long) dp[n][s] * ff[n]) % md;
	}
	printf("%d\n", ans);
	return 0;
}

#include <stdio.h>
#include <string.h>

#define N	200

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int vv[N + 1], ff[N + 1], gg[N + 1];

void init(int md) {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - md % i] * (md / i + 1) % md;
		ff[i] = (long long) ff[i - 1] * i % md;
		gg[i] = (long long) gg[i - 1] * vv[i] % md;
	}
}

int main() {
	static int dp[N + 1][N + 1];
	int n, md, a, b, k, l, s, ans;

	scanf("%d%d", &n, &md), init(md);
	ans = 0;
	for (a = 1; a	<= n + 1; a++) {
		for (k = 0; k <= n; k++)
			memset(dp[k], 0, (a + 1) * sizeof *dp[k]);
		dp[0][0] = 1;
		for (b = a; b <= n + 1; b++) {
			for (k = n; k >= 0; k--)
				for (s = 0; s + (n - k) * (b - a) <= a && s + k * a <= a * (b - 1); s++) {
					int x = dp[k][s], k_, s_, lower, upper;

					if (x == 0)
						continue;
					/* l >= 1
					 * k + l <= n
					 * s + l * (b - a) + (n - (k + l)) * (b + 1 - a) <= a
					 * s + l * (b - a) + (k + l) * a <= a * b
					 *
					 * l >= 1
					 * l <= n - k
					 * l >= s + (n - k) * (b + 1 - a) - a
					 * l <= (a * b - s - k * a) / b
					 */
					lower = max(1, s + (n - k) * (b + 1 - a) - a);
					upper = min(n - k, (a * b - s - k * a) / b);
					for (l = lower; l <= upper; l++) {
						k_ = k + l, s_ = s + l * (b - a);
						dp[k_][s_] = (dp[k_][s_] + (long long) dp[k][s] * gg[l]) % md;
					}
				}
			if (b == a)
				dp[0][0] = 0;
		}
		for (s = 0; s <= a; s++)
			ans = (ans + (long long) dp[n][s] * ff[n]) % md;
	}
	printf("%d\n", ans);
	return 0;
}