#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

bool alive[1001];
int n,m;

int main(){
	while(cin>>n>>m&&n){
		fill(alive,alive+n+1,1);
		int cur=0,a=n;
		while(a>1){
			rep(i,m){
				cur++;
				if(cur>n)cur=1;
				while(!alive[cur]){
					cur++;
					if(cur>n)cur=1;
				}
			}
			alive[cur]=0;
			a--;
		}
		rep(i,n)if(alive[i+1])cout<<i+1<<endl;
	}
}