#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

int main(){
	int m, n;

	while(cin >> n >> m, m+n){
		vector<int> v(n+1);
		int pos = 0;
		for(int i = 0; i < n-1; i++){
			for(int j = 0; j < m; j++){
				pos=pos%n+1;
				while(v[pos] != 0){
					pos=pos%n+1;
				}
			}
			v[pos] = 1;
		}
		for(int i = 1; i < n+1; i++){
			if(!v[i]){
				cout << i << endl;
			}
		}
	}

	return 0;
}