#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    int left[1001],right[1001];
    for(int i=0;i<=n;i++){
      left[i] = i-1;
      right[i] = i+1;
    }
    left[1] = n;
    right[n] = 1;
    int now = 0;
    int cou = n;
    while(cou != 0){
      for(int i=0;i<m;i++){
	now = right[now];
      }
      right[left[now]] = right[now];
      left[right[now]] = left[now];
      cou--;
    }
    cout << now << endl;
  }
}