h,n = map(int,input().split()) c = 1 for i in range(n-1): hs = int(input()) if hs > h: c += 1 if c%10 == 1: print(str(c)+"st") elif c%10 == 2: print(str(c)+"nd") elif c%10 == 3: print(str(c)+"rd") else: print(str(c)+"th")