#include<iostream>
#include<cstring>
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m, n && m){
	bool visited[n+1];
	memset(visited,0,sizeof(visited));
	int j = n,index = m%n;
	if(index == 0)index = n;
	while(j>1){
		visited[index] = true;
		for(int x=0;x<m;++x){
			do{
				index++;
				if(index == n+1)index = 1;
			}while(visited[index]);
		}
		//cout<<index<<endl;
		//visited[index] = true;
		j--;

	}
	for(int x=1;x<=n;++x){
		if(!visited[x]){
			cout<<x<<endl;break;
		}
	}
	}
	return 0;
}