#include <iostream>
using namesspace std;
int main(){
	int n,x,s=0;
	cin >>n;
	cin >>x;

	while(x!=0){
		s+=x;
		if( x>n-x)
		{
			int a=x;
			x=t-x;
			t=a;
		}
		else
		{
			x=t-x;
		}
		cout <<s;
		
	}
}