#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
bool dead[1001];
int n,m;
int main(){
	while(scanf("%d %d",&n,&m) && n){
		memset(dead,0,sizeof(dead));
		int b=1;
		for(int y=0;y<n-1;y++){
			int cou=0;
		for(int i=b;;i++){
			int r=i%n; if(!r) r=n;
			if(!dead[r]){
				cou++;
				if(cou==m){
					dead[r]=true;
					b=i+1;
					break;
				}
			}
		}
		}
		for(int i=1;i<=n;i++){
			if(!dead[i]){
				printf("%d\n",i);
			}
		}
	}
}