play _ _ (x:[]) = x
play m i (th:ts) =
  if m == i
  then play m 1 ts
  else play m (i+1) (ts++[th])

ans [n,m] =
  let t = [1..n]
  in
    play m 1 t

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      i'= takeWhile (/= [0,0]) i
      o = map ans i'
  mapM_ print o