while True:

      n, m = list(map(int, input().split()))

      if n == 0 and m == 0:

            break

      p = [ 1 for i in range(n) ]

      pn = n; count = 0; flag = 1

      while flag == 1:

            for i in range(n):

                  if p[i] == 1:

                        count += 1

                        if count == m:

                              p[i] = 0

                              count = 0

                              pn -= 1

                              if pn == 1:

                                    flag = 0

                                    break



      print(p.index(1)+1)
while True:

      n, m = list(map(int, input().split()))

      if n == 0 and m == 0:

            break

      p = [ i+1 for i in range(n) ]

      np = n; a = 0

      while np > 1:

            a = (a+m-1)%len(p)

            p.pop(a)

            np -= 1

      print(p[0])
while True:
    n, m = list(map(int, input().split()))
    if n == 0 and m == 0:
        break
    p = [1 for i in range(n)]
    pn = n
    count = 0
    flag = 1
    while flag == 1:
        for i in range(n):
            if p[i] == 1:
                count += 1
                if count == m:
                    p[i] = 0
                    count = 0
                    pn -= 1
                    if pn == 1:
                        flag = 0
                        break
    print(p.index(1) + 1)

while True:
    n, m = list(map(int, input().split()))
    if n == 0 and m == 0:
        break
    p = [i + 1 for i in range(n)]
    np = n
    a = 0
    while np > 1:
        a = (a + m - 1) % len(p)
        p.pop(a)
        np -= 1
    print(p[0])

-    p = [1 for i in range(n)] -    pn = n -    count = 0 -    flag = 1 -    while flag == 1: -        for i in range(n): -            if p[i] == 1: -                count += 1 -                if count == m: -                    p[i] = 0 -                    count = 0 -                    pn -= 1 -                    if pn == 1: -                        flag = 0 -                        break -    print(p.index(1) + 1) +    p = [i + 1 for i in range(n)] +    np = n +    a = 0 +    while np > 1: +        a = (a + m - 1) % len(p) +        p.pop(a) +        np -= 1 +    print(p[0])