#include<stdio.h>

int f(int n,int k)
{
  if(n == 1)
    return 0;
  return (f(n-1,k)+k)%n;
}

int main()
{
  while(1)
    {
      int n,k;
      scanf("%d %d",&n,&k);
      if(n+k == 0)
	break;
      printf("%d\n",f(n,k)+1);
    }
}