#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	int n,m;
	
	while(cin>>n>>m,n!=0||m!=0){
		vector<int> p(n);
		for(int i=0;i<n;i++)
			p[i]=i+1;
		int s=0;
		while(1){
			int z=p.size();
			if(z==1)
				break;
			int a =(s+m-1)%z;
			p.erase(p.begin()+a);
			s=a;
		}
		
		cout<<p[0]<<endl;
	}
	
	
	

}