#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,(n||m)){
		bool t[1000]; memset(t,1,sizeof(t));
		int cnt = 0;
		for (int i = 0; i < n-1; i++){
			int a = 0;
			while(a != m - 1){
				while(!t[cnt]) cnt = (cnt+1)%n;
				a++;
				cnt = (cnt+1)%n;
			}
			while(!t[cnt])
				cnt = (cnt+1)%n;
			t[cnt] = false;
		}
		int ans = max_element(t,t+n) - t;
		cout << ans + 1 << endl;
	}
    return 0;
}