from collections import deque N, K = map(int, input().split()) S = [input() for _ in range(N)] num = dict() res = [0] * N for i in range(N): n = 0 for j in range(K): n *= 5 n += 4 - int(S[i][j]) num[n] = i if 0 in num: print(N - 1) exit() dq = deque() dq.append((0, 0)) while dq: now, t = dq.popleft() if now in num: if t == 1: if res[num[now]]: continue res[num[now]] = 1 else: t = 1 a = [] for i in range(K): a.append(now % 5) now //= 5 a.reverse() for i in range(K): if a[i] == 4: continue a[i] += 1 nxt = 0 for j in range(K): nxt *= 5 nxt += a[j] dq.append((nxt, t)) a[i] -= 1 print(sum(res))