import sys input = sys.stdin.readline def to_num(s): ret = 0 for c in s: x = ord(c) - ord('0') ret *= 5 ret += x return ret n, m = map(int, input().split()) items = [to_num(input()[:-1]) for _ in [0] * n] imos = [0] * (5 ** m) for item in items: imos[item] = 1 for i in range(5 ** m): for j in range(m): x = i - (5 ** j) * (i // (5 ** j) % 5) for k in range(3, -1, -1): y = x + (5 ** j) * k imos[y] += imos[y + 5 ** j] ans = sum(imos[item] > 1 for item in items) print(ans)