#include <iostream>
using namespace std;

struct node {
  int key;
  struct node *next;
};

int main() {
  int N,M;
  struct node *t, *x;
  while(cin >> N >> M) {
    if(N==0&&M==0)break;
    t = new node;
    t->key = 1;
    x = t;
    for(int i=2;i<=N;i++) {
      t->next = new node;
      t = t->next;
      t->key = i;
    }
    t->next = x;
    while(t != t->next) {
      for(int i=1;i<M;i++) t = t->next;
      x = t->next; t->next = x->next;
      delete x;
    }
    cout << t->key << endl;
  }
}