n,k = map(int,input().split()) a = sorted(input() for _ in range(n)) x = set() for s in a[::-1]: y = set() for t in x: f = g = False for i in range(k): if s[i]>t[i]: f = True if s[i]