 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;
 
 int main()
 {
   int n,m;
   while(cin>>n>>m&&(n||m))
   {
     list<int> mm;
     list<int>::iterator iter;
     list<int>::iterator iter2;
     for(int i=1;i<=n;i++) mm.push_back(i);
     while(mm.size()>1)
     {
       for(int i=1;i<=m-1;i++)
       {
         mm.push_back(mm.front());
         mm.pop_front();
       }   
       mm.pop_front(); 
       //cout<<mm.front()<<endl;            
     }
     iter=mm.begin();
     cout<<(*iter)<<endl;                
   }
   //while(1);
   return 0; 
 }

 