H,N = map(int,input().split()) rank = 1 for i in range(N-1): h = int(input()) if h > H: rank += 1 rank = str(rank) if rank[-1] == '1': print(rank+'st') elif rank[-1] == '2': print(rank+'nd') elif rank[-1] == '3': print(rank+'rd') else: print(rank+'th')