#include <iostream>
#include <vector>
using namespace std;

int main() {

  int n,m;

  while(true) {

    cin >> n >> m;
    if ( n == 0 ) break;

    int cnt = 0;
    int it;

    vector<int> map;
    for ( int i = 0; i < n; i++ ) {
      map.push_back( i+1 );
    }

    for ( int i = 0; i < n-1; i++ ) {

      cnt = ( cnt + m-1 ) % map.size();

      vector<int>::iterator it = map.begin() + cnt;
      map.erase( it );

    }

    cout << map[0] << endl;

  }

  return 0;

}