#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int n, m;
    while(cin >> n >> m, n || m){
        set<int> s;
        for(int i = 0; i < n; ++i){
            s.insert(i + 1);
        }
        set<int>::iterator it = s.begin();
        while(s.size() > 1){
            for(int i = 0; i < m - 1; ++i){
                it++;
                if(it == s.end()) it = s.begin();
            }
            s.erase(it++);
            if(it == s.end()) it = s.begin();
        }
        
        cout << *(s.begin()) << endl;
    }
}