#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
   int i,j,k,l;
   int a,b,c,d;
   int end_key = 0;
   char end_message = 0;
   int cnt1;
   int e[1000] = {};
   int n,m;
   while(1) {
      cin >> n >> m;
      if(n == 0 && m == 0) break;
      a = 1;
      while(1) {
         b = 0;
         end_key = 0;
         for(i=a;b<m;i++) {
            printf("mae i=%d a=%d b=%d end_key=%d\n",i,a,b,end_key);
            if(e[i] == 0) {
               b++;
            }
            if(i >= n) {
               if(end_key >= b-1) {
                  end_message = 1;
                  break;
               }
               i -= n;
               end_key = b;
            }
            printf("ato i=%d a=%d b=%d end_key=%d\n",i,a,b,end_key);
         }
         a = i;
         if(end_message == 0) {
            e[i-1] = 1;
            printf("kae i=%d a=%d b=%d end_key=%d\n",i,a,b,end_key);
         }
         else break;
      }

      for(i=1;i<n;i++) {
         if(e[i] == 0) {
            printf("%d\n",i);
            break;
         }
      }

   }

   return 0;
}