#include<bits/stdc++.h>
using namespace std;

int mutu(int a,int b){
    if(a<=1) return 0;
    else return (mutu(a-1,b)+b)%a;
}

int main(){
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0&&b==0) break;
        cout<<mutu(a,b)+1<<endl;
    }
    return 0;
}
