#include<cstdio>
#include<vector>

using namespace std;

int main()
{
	int n,m;
	for(;scanf("%d%d",&n,&m),n||m;){
		vector<bool> man(n,true);

		for(int k=0,pos=0;k<n-1;k++){
			for(int cnt=0;;){
				pos=(pos+1)%n;
				if(man[pos]){
					cnt++;
					if(cnt==m)	break;
				}
			}
			man[pos]=false;
		}

		int win;
		for(win=0;!man[win];win++);
		printf("%d\n",win?win:n);
	}

	return 0;
}