import sys input = sys.stdin.readline def fs(l): res = 0 for i in range(K): res += l[i]*pow(5, i) 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): v = S//pow(5, d)%5 if v<4: nS = S+pow(5, d) 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)