inp = raw_input().split(" ")
N, M = int(inp[0]), int(inp[1])
grid1 = []
for i in xrange(N):
grid1.append(raw_input().split())
grid2 = [["" for j in xrange(M)] for i in xrange(N)]
for i in xrange(N):
grid2[i][0] = (1, grid1[i][0])
h = 1
for j in xrange(1,M):
if grid1[i][j] != grid1[i][j-1]:
h += 1
grid2[i][j] = (h, grid1[i][j])
# grid3 = [["" for j in xrange(M)] for i in xrange(N)]
# for j in xrange(M):
# grid3[0][j] = (1, grid1[0][j])
# h = 1
# for i in xrange(1,N):
# if grid1[i][j] != grid1[i-1][j]:
# h += 1
# grid2[i][j] = (h, grid1[i][j])
T = 0
for i in xrange(M):
for j in xrange(i,M):
s = 0
h = 0
for k in xrange(N):
if grid2[k][i][1] != h:
s = 0
h = grid2[k][i][1]
if grid2[k][i] == grid2[k][j]:
s += 1
T += s
else:
s = 0
print T