#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, m;
set<int> si;

int main(){
	while (cin >> n >> m){
		if (n + m == 0)break;
		int a = 0;
		while (si.size() <= n){
			REP(i, m){
				a++;
				if (a > n){
					a = 1;
				}
				while (si.find(a) != si.end()){
					a++;
					if (a > n){
						a = 1;
					}
				}
			}
			si.insert(a);
			if (si.size() == n){
				cout << a << endl;
				break;
			}
		}
		si.clear();
	}
}