#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#include<bitset>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    bitset<1000> person;
    int n, m;
    while(cin >> n >> m, m){
        rep(i,n){
            person[i + 1] = 1;
        }
        int i = 0;
        while(person.any()){
            rep(j,m){
                i++;
                if(i > n){
                    i-= n;
                }
                if(person[i] == 0){
                    j--;
                }
            }
            person[i] = 0;
        }
        cout << i << endl;
    }
}