#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<set>
#include<queue>

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;

int main(){

	int n,m;

	while(true){
		cin>>n>>m;
		
		if(!n&&!m)break;

		vector<int> peoples(n);

		int j = 0,i = 0,c = 0;
		while(c<n-1){
			while(peoples[j] == 1){
				j++;
				j%=n;
			}
			if(i%m == m-1){
				c++;
				peoples[j] = 1;
			}
			i++;
			j++;
			j%=n;
		}

		for(int i=0;i<n;i++){
			if(peoples[i] == 0){
				printf("%d\n",i+1);
				break;
			}
		}

	}

	return 0;
}