#include<iostream>
using namespace std;
int main(){
  int n,m,pc,count;
  while(cin>>n>>m){ 
    if(n==0&&m==0) break;
    int p[n+1];
    p[0] = 0;
    pc = n;
    count = 0;
    for(int i=1;i<=n;i++) p[i] = 1;
    while(pc!=1){
      for(int i=1;i<=n;i++){
	if(p[i]==1) count++;
	if(count==m){
	  p[i] = 0;
	  pc--;
	  if(pc==-1) break;
	  count = 0;
	}
      } 
    }
    for(int i=1;i<=n;i++){
      if(p[i]==1) cout << i << endl;
    }
  }
    return 0;
}