N, K = map(int, input().split())

ans = []
A = int(input())
prev = A
for i, k in enumerate(range(1, N)):
  A = int(input())
  if abs(prev-A) <= 3:
    ans.append(prev)
    if k == N-1:
      ans.append(A)
    prev = A

print(ans)