import sys input = sys.stdin.readline N, K = map(int, input().split()) st = set([input()[:-1] for _ in [0] * N]) visited = set([]) for sv in st: if(sv in visited): continue stk = [sv] while(stk): v = stk.pop() for i in range(K): if(v[i] == '0'): continue nv = ''.join([v[:i], chr(ord(v[i]) - 1), v[i+1:]]) if(nv in visited): continue visited.add(nv) stk.append(nv) ans = len(visited & st) print(ans)