while 1:

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

  if n==0 & m==0: break

  G = list(range(1, n+1))

  while n>1:

    if m%n == 0: G = G[:n-1]

    else: G = G[m % n:] + G[:(m-1) % n]

    n-=1

  print(G[0])
while 1:

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

  if n==0==m:break

  G=list(range(1,n+1))

  p=0

  while n>1:

    p=(p+m-1)%n

    G.pop(p)

    n-=1

  print(G[0])
while 1:
    n, m = list(map(int, input().split()))
    if n == 0 & m == 0:
        break
    G = list(range(1, n + 1))
    while n > 1:
        if m % n == 0:
            G = G[: n - 1]
        else:
            G = G[m % n :] + G[: (m - 1) % n]
        n -= 1
    print(G[0])

while 1:
    n, m = list(map(int, input().split()))
    if n == 0 == m:
        break
    G = list(range(1, n + 1))
    p = 0
    while n > 1:
        p = (p + m - 1) % n
        G.pop(p)
        n -= 1
    print(G[0])

-    if n == 0 & m == 0: +    if n == 0 == m: +    p = 0 -        if m % n == 0: -            G = G[: n - 1] -        else: -            G = G[m % n :] + G[: (m - 1) % n] +        p = (p + m - 1) % n +        G.pop(p)