# 解説のコンセプトから自分でやってみる N, K = map(int, input().split()) S = [] for i in range(N): S.append(input()) S.sort(reverse = True) from collections import deque visited = set() count = 0 for s in S: if s in visited: continue count += 1 que = deque() que.append(s) while que: current = que.popleft() #print('s', s, 'current', current, 'que', que) for k in range(K): if int(current[k]) > 0: new = current[:k] + str(int(current[k])-1) + current[k+1:] if new not in visited: visited.add(new) que.append(new) #print(count) ans = N - count print(ans)