import sys readline = sys.stdin.readline N, K = map(int, readline().split()) D = [[[[[[[[0] * 6 for _ in range(6)] for _ in range(6)] for _ in range(6)] for _ in range(6)] for _ in range(6)] for _ in range(6)] for _ in range(6)] S = [] for i in range(N): s = readline().rstrip() s = str(s).zfill(8) s = list(s) s = list(map(int, s)) s = list(map(lambda x : 4 - x, s)) s = list(map(str, s)) s = "".join(s) S.append(s) i,j,k,l,m,n,o,p = map(int,s) D[i + 1][j + 1][k + 1][l + 1][m + 1][n + 1][o + 1][p + 1] += 1 for i in range(6): for j in range(6): for k in range(6): for l in range(6): for m in range(6): for n in range(6): for o in range(6): for p in range(5): D[i][j][k][l][m][n][o][p + 1] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(6): for k in range(6): for l in range(6): for m in range(6): for n in range(6): for o in range(5): for p in range(6): D[i][j][k][l][m][n][o + 1][p] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(6): for k in range(6): for l in range(6): for m in range(6): for n in range(5): for o in range(6): for p in range(6): D[i][j][k][l][m][n + 1][o][p] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(6): for k in range(6): for l in range(6): for m in range(5): for n in range(6): for o in range(6): for p in range(6): D[i][j][k][l][m + 1][n][o][p] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(6): for k in range(6): for l in range(5): for m in range(6): for n in range(6): for o in range(6): for p in range(6): D[i][j][k][l + 1][m][n][o][p] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(6): for k in range(5): for l in range(6): for m in range(6): for n in range(6): for o in range(6): for p in range(6): D[i][j][k + 1][l][m][n][o][p] += D[i][j][k][l][m][n][o][p] for i in range(6): for j in range(5): for k in range(6): for l in range(6): for m in range(6): for n in range(6): for o in range(6): for p in range(6): D[i][j + 1][k][l][m][n][o][p] += D[i][j][k][l][m][n][o][p] for i in range(5): for j in range(6): for k in range(6): for l in range(6): for m in range(6): for n in range(6): for o in range(6): for p in range(6): D[i + 1][j][k][l][m][n][o][p] += D[i][j][k][l][m][n][o][p] ans = 0 for s in S: i,j,k,l,m,n,o,p = map(int,s) if D[i + 1][j + 1][k + 1][l + 1][m + 1][n + 1][o + 1][p + 1] >= 2: ans += 1 print(ans)