#include <iostream>
#include <cstring>
using namespace std;

int main(){
    int n,m,cnt,tmp,loop;
    while(cin >> n >> m,m && n){
        cnt = 0;
        tmp = n;
        loop = 0;
        bool ju[n+1];
        memset(ju,true,sizeof(ju));
        while(1){
            do{
                (tmp == n)? tmp = 1 : tmp++;
            }while(!ju[tmp]);
            cnt++;
            if(loop == n-1) break;
            if(cnt == m) {
                cnt = 0;
                loop++;
                ju[tmp] = false;
            }
        }
        for(int i=1;i<n+1;i++){
            if(ju[i]){
                cout << i << endl;
                break;
            }
        }
    }
}