#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,people,now[1001],poteto=1;;
    while(1){
        cin>>n>>people;
        if(n==0&&people==0)break;
        for(int i=1;i<=n;i++)now[i]=1;
        for(int i=0;i<n-1;i++){
            for(int j=0;j<people;j++){
            if(now[poteto]!=0){
                now[poteto]=1;
                for(int k=poteto;;k++){
                    if(k>n)k=1;
                    if(now[k]==1){
                            now[k]=2;
                            break;
                    }
                }
            }
            else j--;
            if(j==people-1){
                    now[poteto]=0;
                   // cout<<poteto<<endl;
            }
            poteto++;
            if(poteto>n)poteto=1;
        }
        }
        for(int i=1;i<=n;i++){
                if(now[i]==2||now[i]==1){
                    cout<<i<<endl;
                    break;
                }
        }
        poteto=1;
    }
}