#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int N,M;
	while(cin>>N>>M,N||M){
		bool is_die[1000]={};
		for(int i=0,cntM=1,cntH=N;;i=++i%N){
			if(is_die[i]==true) continue;
			if(cntH==1){
				printf("%d\n",i+1);
				break;
			}
			if(cntM==M){
				is_die[i] = true;
				cntH--;
				cntM = 0;
			}
			cntM++;
		}
	}
	return 0;
}