#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;



int ret_num(int n, int m, int cheak[1000], int *num){
    if(m==1&&cheak[*num]==0)return *num;
    if(m==1||cheak[*num]==1){
        *num=(*num+1)%n;
        return ret_num(n, m, cheak, num);
    }
    *num=(*num+1)%n;
    return ret_num(n, m-1, cheak, num);
}


int main(void)
{
    int n,m;
    
    while(cin>>n>>m){
        int counter = n;
        int num = 0;
        int cheak[1000]={0};
        if(n==0&&m==0)break;
        while(counter!=1){
            counter--;
            cheak[ret_num(n, m, cheak, &num)]=1;
            /*for(int i=0; i<n; i++){
                cout<<setw(3)<<i+1;
            }cout<<endl;
            for(int i=0; i<n; i++){
                cout<<setw(3)<<cheak[i];
            }cout<<endl;*/
        }
        for(int i=0; i<n; i++){
            if(cheak[i]==0){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    
    
}