H, N = input().strip().split(' ') H, N = int(H), int(N) high = 1 for i in range(N - 1): tmp = int(input().strip()) if tmp > H: high += 1 if high % 10 == 1: tmp = str(high) + 'st' elif high % 10 == 2: tmp = str(high) + 'nd' elif high % 10 == 3: tmp = str(high) + 'rd' else: tmp = str(high) + 'th' print(tmp)