from functools import lru_cache n,k = map(int,input().split()) a = {tuple(map(int,input())) for _ in range(n)} @lru_cache def main(s): for i in range(k): if s[i]<5: t = list(s); t[i] += 1; t = tuple(t) if t in a or main(t): return True return False ans = 0 for s in a: if main(s): ans += 1 print(ans)