#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n,m,cnt,t,ans,cnt2;
bool num[1000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		rep(i,1000) num[i] = false;
		cnt = 0; cnt2 = 0;
		t = 0;
		while(true){
			if(!num[t]){
				cnt++;
				cnt2=0;
				if(cnt%m==0){
					num[t] = true;
					ans = t;
				}
			}
			if(t == n-1) t = -1;
			t++;
			cnt2++;
			if(cnt2 > n+10) break;
		}
		cout << ans+1 << endl;
	}
}