#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int n, m;
    while ( cin >> n >> m ) {
        if ( n == 0 && m == 0 ) break;
        vector <int> M( n );
        for ( int i = 0; i < n; ++ i ) {
            M[i] = i + 1;
        }

        int ind = 0;
        for ( int i = 0; i < n - 1; ++ i ) {
            ind = ( ind + m - 1 ) % M.size();
            M.erase( M.begin() + ind );
        }

        cout << M[0] << endl;
    }
    return 0;
}