#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m && n||m){
    int cnt = n,ban = 1,cnter; bool ok[n+1];
    memset(ok,true,sizeof(ok));
    while(true){
      cnter = 0;
      do{
	do{
	  (ban==n) ? ban=1:ban++;
	}while(!ok[ban]);
	cnter++;
      }while(cnter!=m);
      cnt--;
      ok[ban] = false;
      if(cnt == 1) break;
    }
    for(int i=1;;i++){
      if(ok[i]){
	cout << i-1 << endl;
	break;
      }
    }
  }
}