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

int main(){

  int a[10000];
  int n,m;
  int k,r,z;

  while(true){
    cin >> n >> m;
    if(!n && !m) break;

    memset(a,-1,sizeof(a));
    k = r = z = 1;

    while(true){

      if(k == n) break;
      if(z > n) z  = 1;
      if(r > m) r = 1;

      if(a[z] == -1&& r == m){
	a[z] = 0;
	r++;
	k++;
      }

      if(a[z]) r++;
      z++;

    }

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

  }
}