#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int main(){
    int N, M;
    while(std::cin >> N >> M, N && M){
        std::vector<int> v;
        REP(i, N){
            v.push_back(i);
        }
     
        int pos = 0;
        while(v.size() > 1){
            pos = (pos + M) % v.size();
            // printf("Exit: %d\n", v[pos]);
            v.erase(v.begin() + pos);
            pos = (pos + v.size() - 1) % v.size();
        }

        int res = v[0]>0?v[0]:N;
        printf("%d\n", res);
    }

    return 0;
}