#include<cstdio>
using namespace std;
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n,m){
        bool stage[1024] = {0};
        int q = 1,x = 1;
        int cnt = 0,q_cnt = 0;
        for(;;){
            for(int i = x;;){
                if(stage[i] == 0)q_cnt++;
                if(q_cnt == m){
                    x = i;
                    q_cnt = 0;
                    break;
                }
                ++i;
                if(i > n)i -= n;
            }
            stage[x] = 1;
            cnt++;
            if(cnt == n-1)break;
        }
        for(int i = 1;i <= n; i++){
            if(stage[i] == 0){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}