#include <iostream>

using namespace std;

int main(){
        int n,m;
        cin >> n >> m; 
        while(n){
                bool *a = new bool[n];
                for(int i = 0; i<n; i++) a[i] = true;
                int idx = n-1;
                int _n = n; 
                while(n--){
                        int c = m; 
                        while(c){
                                idx = (idx+1)%_n;
                                if(a[idx]) --c;
                        }  
                        a[idx] = false;
                }  
                delete a; 
                cout << ++idx << endl;
                cin >> n >> m; 
        }  
}