#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return acos(-1.0);
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int n,m,sr,star,ans,i;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		else{
			vi ss(n,1);
			ans=0;
			sr=n;
			star=0;
			while(1){
				int count=0;
				for(i=star;count<=m;i++){
					if(sr==1) break;
					if(i<=n){
						if(ss[i]==1){
							count++;
							if(count==m) break;
						}
					}
					else{
						if(ss[i-n]==1){
							count++;
						}
					}
					if(i==n) i=-1;
				}
				if(sr==1) break;
				cout<<i<<endl;
				ss[i]=0;
				if(i<=n) star=i;
				else{
					star=i-n;
				}
				sr--;
			}
			for(i=0;i<n;i++){
				if(ss[i]==1){
					ans=i+1;
					break;
				}
			}
			cout<<ans<<endl;
		}
	}
}