#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(){
 
    int n,m,count,tmp;
 
    while(true){
        scanf("%d %d",&n,&m);
        if(n == 0 && m == 0)break;
 
        count = n;
        int array[n];
        for(int i=0; i < n; i++)array[i] = 1;
 
        tmp = 0;
        for(int i=0;count > 1;){
            if(array[i] == 1){
                tmp++;
                if(tmp == m){
                    array[i] = 0;
                    count--;
                    tmp = 0;
                    i = (i+1)%n;
                }else{
                    i = (i+1)%n;
                }
            }else{
                i = (i+1)%n;
            }
        }
 
        for(int i=0; i < n; i++){
            if(array[i] == 1)printf("%d\n",i+1);
        }
 
    }
 
    return 0;
}
