#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int main(){
      int n,m;
      while(cin>>n>>m&&n&&m){
            int turn=n-1;
            int nxt[n],bfr[n];
            REP(i,n)nxt[i]=(i+1)%n;
            REP(i,n)bfr[i]=(i-1+n)%n;
            while(nxt[turn]!=turn){
                  REP(j,m){
                        turn=nxt[turn];
                  }
                  nxt[bfr[turn]]=nxt[turn];
                  bfr[nxt[turn]]=bfr[turn];
            }
            cout<<turn+1<<endl;
      }
}