#include<iostream>
#include<string.h>
using namespace std;

int main() {
  int n,m;
  while(true) {
    cin>>n>>m;
    if(!n) break;

    int *v = new int[n];
    for(int i=0; i<n; i++) v[i] = 1;

    int curr=-1;
    for(int i=0; i<n-1; i++) {
      for(int j=1; j<=m; j++) {
	if(v[(curr+j)%n] == 0) j--,curr++;
	if(j==m) {
	  v[(curr+j)%n] = 0;
	  curr = (curr+j)%n;
	}
      }
    }

    for(int i=0; i<n; i++)
      if(v[i]==1) cout<<i+1<<endl;
  }
}