l, n = map(int, input().split()) length = [int(input()) for _ in range(n-1)] ans = length + [l] ans.sort(reverse=True) for i in range(len(ans)): if ans[i] == l: if i % 10 == 0: print(f'{i+1}st') elif i % 10 == 1: print(f'{i+1}nd') elif i % 10 == 2: print(f'{i+1}rd') else: print(f'{i+1}th')