#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect import heapq import functools mod=10**9+7 import sys input=sys.stdin.readline n,m=map(int,input().split()) s=[input().rstrip() for _ in range(n)] ans = 0 for i in range(26): for j in range(m+1): tmp = [] for k in range(j): tmp.append(s[0][k]) tmp.append(chr(i+ord('a'))) for k in range(j,m): tmp.append(s[0][k]) for ii in range(1,n): now = 0 for k in range(m+1): if now < m and tmp[k] == s[ii][now]: now += 1 if now != m: break else: ans += 1 print(ans)