N = int(input())
M = int(input())
recommend = list(map(int, input().split()))
slot = dict()
cnt = 0
for rec in recommend:
# 슬롯이 꽉 차있는 상태에서 교체해야 하는 경우
if len(slot) >= N and not rec in slot:
# 가장 갯수가 적은 것을 삭제함
del slot[min(slot, key=lambda x:slot[x])]
# 이미 있는 거면 추천 수를 하나씩 추가함
try: slot[rec][0] += 1
# 새로 추가했다면 카운트를 하나씩 추가함
except:
slot[rec] = [1, cnt]
cnt += 1
print(*sorted(slot.keys()))
아직 제대로 해시를 잘 사용하지 못하는 것 같다.