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