#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;


int main(void) {

  int n, m;
  while(cin >> n >> m){
    if( n == 0||m==0 ) break;

    int cnt = 0;
    vector<bool> b(n, true);
    int a = n;
    int pos = 0;
    while(true){
      pos %= n;
      pos++;
      if( !b[pos] ) continue;
      cnt++;
      if( cnt == m ){
        b[pos] = false;
        a--;
        // cerr << pos << endl;
        if( a == 0 ){
          cout << pos << endl;
          break;
        }
        cnt = 0;
      }
    }

  }


  return 0;
}


// EOF