#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
  int m, n;
  
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    
    vector<int> person(n+1);
    
    for(int i = 1 ; i <= n ; i++){
      person[i] = i;
    }
    int cnt = 1;
    
    for(vector<int>::iterator it = person.begin()+1 ; person.size() != 1 ;){
      if(it == person.end()) it = person.begin()+1;
      
      if(cnt % m == 0) it = person.erase(it);
      else it++;
      cnt++;
    }
    
    cout << person[1] << endl;
  }
  return 0;
}