  #include<iostream>
using namespace std;

int potato(int x, int y)
{
 int i;
 for(i=y-1; i<(y-1)*x; i = (y*i)/(y-1)+1)
 return(y*x-i);
 }
 int main()
{
 int x,y;
 while(cin>>x>>y, x || y)
 {
  cout<<potato(x , y)<<endl;
  }
 }