정답코드
import sys
input=sys.stdin.readline
n=int(input())
student=int(input())
candidate={}
for idx,i in enumerate(list(map(int,input().split()))):
if i in candidate:
candidate[i][2]+=1
else:
if(len(candidate)==n):
del candidate[sorted(list(candidate.values()),key=lambda x:(-x[2],-x[1]))[-1][0]]
candidate[i]=[i,idx,1]
print(' '.join(list(map(str,sorted(candidate.keys())))))