#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        list<int> a;
        for(int i=1; i<=n; ++i)
            a.push_back(i);

        list<int>::iterator it = a.begin();

        for(int i=0; i<n-1; ++i){
            for(int i=0; i<m-1; ++i){
                ++ it;
                if(it == a.end())
                    it = a.begin();
            }
            it = a.erase(it);
            if(it == a.end())
                it = a.begin();
        }

        cout << *it << endl;
    }
}