#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int main(){
  queue<int>que;

  int n,m;
  while( cin >> n >> m,n + m){
    while(!que.empty())que.pop();
    for(int i = 1 ; i <= n ; i++ )que.push(i);
    int cnt = 0;
    while(que.size() != 1){
      cnt++;
      if(cnt == m){
	cnt = 0;
	que.pop();
      } else {
	que.push(que.front());
	que.pop();
      }
    }
  cout << que.front() << endl;
  }
  return 0;
}