#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n,m;
  while(cin >> n >> m){
    if(n==0&&m==0) break;
    queue<int> line;
    REP(i,n) line.push(i+1);
    
    int num=0;
    while(line.size()!=1){
      int a = line.front();
      line.pop();
      num++;
      if(num == m)
	num = 0;
      else
	line.push(a);
    }
    cout << line.front() << endl;
  }

  return 0;
}