CodeForces 460 A. Vasya and Socks(379A.New Year Candles)

来源:互联网 发布:淘宝大学金牌讲师小飞 编辑:程序博客网 时间:2024/05/19 13:20

A. Vasya and Socks

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Output

Print a single integer — the answer to the problem.

Examples

input

2 2

output

3

input

9 3

output

13

Note

In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.

In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

百度翻译:Vasya有N双袜子。在每一天早上有Vasya上学之前穿上一双袜子。当他晚上回到家,Vasya脱下袜子扔了。每一个m天(天数m,  2m,3m, …)妈妈买了一双袜子,Vasya。她在晚上,所以Vasya不能穿上一双新袜子在明天之前。多少天过去直到Vasya耗尽的袜子吗?

输入

一行包含两个整数n和m(1 ≤ N ≤ 100;2 ≤ M ≤ 100),用一个空格隔开。

输出

打印一个整数——问题的答案。

实例

输入

2 2

输出

输入

9 3

输出

十三

在第一个样品Vasya花的头两天穿,他最初的袜子。然后在第三天,他穿上了第二天买的袜子。

在样本二Vasya花的前九天,他开始穿袜子。然后他花了三天穿上第三、第六、第九天买的袜子。他花了一天的时间穿上第十二天买的袜子。

#include <cstring>

#include <cstdio>

#include <iostream>

#include <algorithm>

using namespace std;

int main()

{

    int n,m;

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

    int sum=0,i,j;

    for(i=n,j=1;i>0;i--,j++)

    {

        if(j%m==0)

            i++;

        sum++;

    }

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

    return 0;

}