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

// #define int long long

/* short */
#define pb push_back
#define print(Target) cout << Target << '\n'

/* REPmacro */
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

/* const */
const int INF = INT_MAX;

signed main()
{
  ios::sync_with_stdio(false);
  int n, m;

  while (cin >> n >> m, n || m){
    int less = n, cnt = 0;
    bool t[1024];
    memset(t, true, sizeof(t));
    for (int i = 1;; i++){
      if (t[i]){
        if (cnt == m - 1){
          t[i] = false;
          less--;
          cnt = 0;
          // cout << "t[" << i << "]" << " is " << "nuke" << endl;
          if (less == 0){
            print(i);
            break;
          }
        }else {
          cnt++;
        }
      }
      if (i + 1 > n){
        i = 0;
      }
    }
  }
  
  return (0);
}