import sys input = sys.stdin.readline def fs(l): res = 0 for i in range(K): res += l[i]*pow(5, i) return res def fl(s): res = [] for i in range(K): res.append(s%5) s //= 5 return res N, K = map(int, input().split()) exist = [0]*pow(5, K) cnt = [0]*pow(5, K) for _ in range(N): l = list(map(int, list(input()[:-1]))) exist[fs(l)] = 1 cnt[fs(l)] = 1 for d in range(K): for S in range(pow(5, K)-1, -1, -1): l = fl(S) if l[d]<4: nS = fs(l[:d]+[l[d]+1]+l[d+1:]) cnt[S] += cnt[nS] ans = 0 for S in range(pow(5, K)): if exist[S]==1 and cnt[S]>1: ans += 1 print(ans)