import sys sys.setrecursionlimit(1 << 25) def main(): N, K = map(int, sys.stdin.readline().split()) # Precompute for x in [0 ... N], whether (x, f) is a losing position. # We use a memoization approach but due to large N and K, this will not work for actual large cases. # This code is a theoretical approach and may not handle all cases efficiently. max_x = N F = [set() for _ in range(max_x + 1)] # F[x] = set of f's where (x, f) is a losing position. for x in range(max_x, -1, -1): for f in range(0, K + 1): allowed_ds = [] for d in range(1, K + 1): if d == f: continue if x + d >= N: continue allowed_ds.append(d) # Check if all allowed_ds lead to (x + d, d) being a winning position for opponent. # i.e., if for all d in allowed_ds, d is NOT in F[x + d] all_lead_to_win = True for d in allowed_ds: next_x = x + d if next_x >= N: continue # Opponent can't make this move, so skip if d in F[next_x]: all_lead_to_win = False break if all_lead_to_win: F[x].add(f) # Collect possible initial moves result = [] for d in range(1, K + 1): if d >= N: continue # invalid move, since adding d to 0 gives d >=N # Check if (d, d) is a losing position for Grant. if d in F[d]: result.append(d) if result: result.sort() for num in result: print(num) else: print(0) if __name__ == '__main__': main()