#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  while(1){
    int n,m;

    cin>>n>>m;
    if(n==0 &&m==0)break;
    int order[1000]={};
    int i;
    int cnt=1;
    int num=1;
    while(num>0){
      rep(i,n){
	if(order[i])continue;
	if(cnt==m){
	  order[i]=num;
	  cnt=0;
	  if(num==n){
	    num=-1;
	    break;
	  }
	  num++;
	}
	cnt++;
      }
    }
    rep(i,n)
      if(order[i]==n){
	cout<<i+1<<endl;
	break;
      }
  }
}