#include <iostream>
#include <vector>
using namespace std;
struct obj
{
  int m_num;
  obj* m_prev;
  obj* m_next;
  void set(int n,obj* prev){
    m_num = n;
    m_prev = prev;
    prev->m_next = this;
  }
};
int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<obj> v(n);
    for(int i=1; i<n; i++){
      v[i].set(i+1,&v[i-1]);
    }
    v[0].set(1,&v[n-1]);

    obj* p = &v[0];
    int count = 1;
    while(p->m_next != p){
      p = p->m_next;
      if(++count == m){
        count = 1;
        p->m_prev->m_next = p->m_next;
        p->m_next->m_prev = p->m_prev;
        p = p->m_next;
      }
    }
    cout << p->m_num << endl;
  }
  return 0;
}