#include <iostream>
#include <cstring>
using namespace std;

int main(void){
  int dp[1001], n, m;
  while(cin >> n >> m && n && m){
    memset(dp, 0, sizeof(dp));
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
      dp[i] = (dp[i-1] + m) % i;
    }
    cout << dp[n] + 1 << endl;
  }
  return 0;
}