# Count max prefix instead of prefix sum
from itertools import takewhile

INF = 1e9

n, e = map(int, input().split())
keys = [input() for _ in range(n)]

def count(key, c):
    l = len(list(takewhile(lambda cc: cc == c, key)))
    return INF if l == len(key) else l

l, c = min((
        (max(count(key, c) for key in keys), c) 
        for c in (chr(i + ord('a')) 
        for i in range(e))
    ))
print('NO' if l == INF else c * (l + 1))
