#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,n) for(__typeof((n).begin()) it=(n).begin();it!=(n).end();++it)

using namespace std;

class Sequence {
public:
    typedef long long Int;
    static const Int INF = 1LL << 60;
    
    struct Node {
        Node* ch[2];
        Int val, valMax, valMin, sum;
        Int lazy;
        int size;
        
        Node(Int v) {
            for (int i = 0; i < 2; i++) ch[i] = NULL;
            val = valMax = valMin = sum = v;
            lazy = 0;
            size = 1;
        }
    };
    
    Node *root;
    
    Sequence() {
        root = NULL;
    }
    
    void print() { print(root = update(root)); cout << endl; }
    int size() { return count(root = update(root)); }
    int height() { return height(root = update(root)); }
    Int max(int l, int r) { return max(root = update(root), l, r); }
    Int min(int l, int r) { return min(root = update(root), l, r); }
    Int sum(int l, int r) { return sum(root = update(root), l, r); }
    void add(int l, int r, Int v) { return add(root = update(root), l, r, v); }
    
    void insert(int k, Int v) {
        pair<Node*, Node*> nodes = split(root, k);
        root = merge(nodes.first, merge(newNode(v), nodes.second));
    }
    
    void erase(int k) {
        pair<Node*, Node*> A, B;
        A = split(root, k + 1);
        B = split(A.first, k);
        root = merge(B.first, A.second);
    }
    
    void push_back(Int v) {
        insert(this->size(), v);
    }
    
    Int get(int i) {
        return get(root = update(root), i);
    }
    
    Int operator[](const int &i) { return get(i); }
    
    ////////////////////////////////////////////////
    void print(Node *node) {
        if (!node) return;
        updateChildren(node);
        print(node->ch[0]);
        cout << node->val << " ";
        print(node->ch[1]);
    }
    
    Node *newNode(Int v) {
        Node* node = new Node(v);
        return node;
    }
    
    Node *update(Node *node) {
        if (!node) return node;
        if (node->lazy) {
            Int v = node->lazy;
            for (int i = 0; i < 2; i++) {
                Node* c = node->ch[i];
                if (c) {
                    c->lazy += v;
                    c->val += v;
                    c->valMax += v;
                    c->valMin += v;
                    c->sum += v * (Int)c->size; 
                }
            }
            node->lazy = 0;
        }
        node->size = count(node->ch[0]) + count(node->ch[1]) + 1;
        node->valMax = std::max(max(node->ch[0]), std::max(node->val, max(node->ch[1])));
        node->valMin = std::min(min(node->ch[0]), std::min(node->val, min(node->ch[1])));
        node->sum = sum(node->ch[0]) + node->val + sum(node->ch[1]);
        return node;
    }
    
    void updateChildren(Node *node) {
        for (int i = 0; i < 2; i++) {
            node->ch[i] = update(node->ch[i]);
        }
    }
    
    Node *merge(Node *left, Node *right) {
        if (!left) return right;
        if (!right) return left;
        
        int cleft = count(left), cright = count(right);
        
        if (rand() % (cleft + cright) < cleft) {
            left = update(left);
            left->ch[1] = merge(left->ch[1], right);
            return update(left);
        }
        right = update(right);
        right->ch[0] = merge(left, right->ch[0]);
        return update(right);
    }
    
    pair<Node*, Node*> split(Node *node, int k) {
        if (!node) return make_pair(node, node);
        node = update(node);
        if (k <= count(node->ch[0])) {
            pair<Node*, Node*> s = split(node->ch[0], k);
            node->ch[0] = s.second;
            return make_pair(s.first, update(node));
        }
        pair<Node*, Node*> s = split(node->ch[1], k - count(node->ch[0]) - 1);
        node->ch[1] = s.first;
        return make_pair(update(node), s.second);
    }
    
    int count(const Node *node) { return !node ? 0 : node->size; }
    Int max(Node *node) { return !node ? -INF : node->valMax; }
    Int min(Node *node) { return !node ? INF : node->valMin; }
    Int sum(Node *node) { return !node ? 0 : node->sum; }
    
    Int max(Node *node, int l, int r) {
        if (!node) return -INF;
        
        updateChildren(node);
        
        int c = count(node->ch[0]);
        if (r <= 0 || node->size <= l) return -INF;
        if (r <= c) return max(node->ch[0], l, r);
        if (c < l) return max(node->ch[1], l - c - 1, r - c - 1);
        if (l == 0 && r == node->size) return node->valMax;
        return std::max(node->val, std::max(max(node->ch[0], l, count(node->ch[0])),
                                            max(node->ch[1], 0, r - c - 1)));
    }
    
    Int min(Node *node, int l, int r) {
        if (!node) return INF;
        
        updateChildren(node);
        
        int c = count(node->ch[0]);
        if (r <= 0 || node->size <= l) return INF;
        if (r <= c) return min(node->ch[0], l, r);
        if (c < l) return min(node->ch[1], l - c - 1, r - c - 1);
        if (l == 0 && r == node->size) return node->valMin;
        return std::min(node->val, std::min(min(node->ch[0], l, count(node->ch[0])),
                                            min(node->ch[1], 0, r - c - 1)));
    }
    
    Int sum(Node *node, int l, int r) {
        if (!node) return 0;
        
        updateChildren(node);
        
        if (r <= 0 || node->size <= l) return 0;
        int c = count(node->ch[0]);
        if (r <= c) return sum(node->ch[0], l, r);
        if (c < l) return sum(node->ch[1], l - c - 1, r - c - 1);
        if (l == 0 && r == node->size) return node->sum;
        return sum(node->ch[0], l, count(node->ch[0])) + node->val + sum(node->ch[1], 0, r - c - 1);
    }

    void add(Node *node, int l, int r, Int v) {
        if (!node) return;
        
        updateChildren(node);
        
        if (r <= 0 || node->size <= l) return;
        int c = count(node->ch[0]);
        if (r <= c) return add(node->ch[0], l, r, v);
        if (c < l) return add(node->ch[1], l - c - 1, r - c - 1, v);
        if (l == 0 && r == node->size) {
            node->lazy += v;
            node->val += v;
            node->valMax += v;
            node->valMin += v;
            node->sum += v * (Int)node->size; 
            return;
        }
        add(node->ch[0], l, count(node->ch[0]), v);
        node->val += v;
        add(node->ch[1], 0, r - c - 1, v);
        update(node);
    }

    Int get(Node *node, int index) {
        if (!node) throw("out of bound");
        updateChildren(node);
        int c = count(node->ch[0]);
        if (index < c) return get(node->ch[0], index);
        if (index == c) return node->val;
        return get(node->ch[1], index - c - 1);
    }
    
    int height(Node *node) {
        if (!node) return 0;
        updateChildren(node);
        return std::max(height(node->ch[0]), height(node->ch[1])) + 1;
    }
};

Sequence seq;

void qu() {
    int l, r;
    cin >> l >> r;
    l--;
    cout << seq.min(l, r) << endl;
}

void add() {
    int l, r, k;
    cin >> l >> r >> k;
    l--;
    seq.add(l, r, k);
}

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        Sequence seq;
        rep(i, n) {
            seq.push_back(i + 1);
        }
        int index = -1;
        for (int i = n; i > 1; i--) {
            //seq.print();
            index = (index + m) % i;
            seq.erase(index);
            index--;
        }
        cout << seq[0] << endl;
    }

    return 0;
}