#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
    int n, m;
    
    while (1){
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        vector <int> number;
        for (int i = 1; i <= n; i++){
            number.push_back(i);
        }
        vector <int> :: iterator it = number.begin();
        while (1 < number.size()){
            for (int i = 1; it = (it == number.end()) ? number.begin() : it, i < m; i++){
                it++;
            }
            it = number.erase(it);
        }
        printf("%d\n", number[0]);
    }
    
    return (0);
}