#include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int r[n+1];
    for(int i=1;i<=n;i++) r[i] = i+1;
    r[n] = 1;
    int p = n,next,newnext;
    while(1){
      for(int i=1;i<m;i++) p = r[p];
      next = r[p];
      newnext = r[next];
      if(next==newnext){
	cout << next << endl;
	break;
      }
      r[p] = newnext;
    }
  }
  return 0;
}