n,k = map(int,input().split()) a = {tuple(map(int,input())) for _ in range(n)} d = {} for i in range(5**k-1, -1, -1): t = [] for _ in range(k): t.append(i%5); i //= 5 t = tuple(t); f = False for j in range(k): if t[j]<4: u = list(t); u[j] += 1; u = tuple(u) f |= u in a or d[u] d[t] = f ans = 0 for s in a: ans += d[s] print(ans)