# your code goes here H,N=(int(i) for i in input().split()) c=0 for i in range(N-1): # print(c) g=int(input()) if g>H: c+=1 S=str(c+1) T=S[-1] if T=="1": d="st" elif T=="2": d="nd" elif T=="3": d="rd" else: d="th" print(S+d)