#include <iostream>
using namespace std;
#define MAX 1000

int main(){
  int n,m,player[MAX];

  for(;;){
    for(int i = 0 ; i < MAX ; i++) player[i] = 0;

    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(int i = 0 ; i < n ; i++) player[i] = 1;
    
    int cnt = 0,num = 0,endcnt=0;    
    while(1){
      if(endcnt == n - 1) break;
      cnt++;
      if(cnt == m){
        num += m;
        if(num > n) num -= n;
        player[num-1] = 0;
        cnt = 0;
        endcnt++;
      }
    }
    for(int i = 0 ; i < n ; i++){
      if(player[i] != 0){
      cout << i+1 << endl;
      break;    
      }
    } 
  }

  return 0;
}