base, n = map(int, input().split()) res = 1 for i in range(1, n): if int(input()) > base: res += 1 res = str(res) if res[-1] == 1: print(res + "st") elif res[-1] == 2: print(res + "nd") elif res[-1] == 3: print(res + "rd") else: print(res + "th")