#include <iostream>
#include <algorithm>

using namespace std;

bool allvisited(bool visited[], int n){
	for(int i=1;i<=n;i++){
		if(visited[i] == false){
			return false;
		}
	}
	return true;
}

int main(void){
	int n,m;
	
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		bool visited[n+1]; //numbers are 1-origin
		fill(visited, visited+n+1, false);
		
		int place = n;
		while(!allvisited(visited, n)){
			int cnt=0;
			while(cnt != m){
				place++;
				if(place > n) place -= n;
				if(visited[place] == true) continue;
				cnt++;
			}
			visited[place] = true;
		}
		cout << place << endl;
	}
}