#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, m;
	
	bool ID[5000];
	
	while(true){
		
		cin >> n >> m;
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(int i = 0; i <= n; i++){
			ID[i] = true;
		}
		
		int j = 1;
		
		for(int i = 0; i < n - 1; i++){
			int count = 0;
			while(true){
				if(ID[j]){
					count++;
					if(count == m){
						//cout << j << " ";
						ID[j] = false;
						break;
					}
				}
				j++;
				if(j > n){
					j -= n;
				}
			}
		}
		
		for(int i = 1; i <= n; i++){
			if(ID[i]){
				printf("%d\n",i);
			}
		}
		
	}
	return 0;
}