//Joseph's Potato
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, m;
  while(true){
    cin>>n>>m;
    if(n==0&&m==0)break;
    queue<int> q;
    int ans;
    for(int i=0; i<n; i++)q.push(i);
    while(q.size()!=1){
      for(int i=0; i<m-1; i++){q.push(q.front()); q.pop();}
      q.pop();
    }
    cout<<q.front()+1<<endl;
  }
  return 0;
}