#include<iostream>

using namespace std;

int main(){

  int n, m;

  while(1){
    cin >> n >>  m;
    if(n == 0 && m == 0) break;

      int data[n+1];
      for(int i = 1; i <= n; i++) data[i] = 1;
      int sum = 0;
      int del = 0;
      int status = 0;
      while(1){
	for(int i = 1; i <= n; i++){
	  if(data[i] == 1){
	    sum++;
	  }
	  if(sum == m){
	    data[i] = 0;
	    del++;
	    sum = 0;
	  }
	  if(del == n-1){
	    status = 1;
	    break;
	  }
	}

	if(status == 1) break;
      }

      for(int i = 1; i <= n; i++){
	if(data[i] == 1){
	  cout << i << endl;
	  break;
	}
      }
  }
  return 0;
}