import sys #input = sys.stdin.readline #input = sys.stdin.buffer.readline #文字列はダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] #dx8 = [1,1,0,-1,-1,-1,0,1] #dy8 = [0,1,1,1,0,-1,-1,-1] class RollingHash(): def __init__(self, s, base, mod): self.mod = mod self.pw = pw = [1]*(len(s)+1) l = len(s) self.h = h = [0]*(l+1) v = 0 for i in range(l): h[i+1] = v = (v * base + ord(s[i])) % mod #文字ではなく数字のリストの場合はord不要 v = 1 for i in range(l): pw[i+1] = v = v * base % mod def get(self, l, r): #S[l:r)indexでいうl文字目からr-1文字目 return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod base1 = 1007; base2 = 2009 mod1 = 1000000007; mod2 = 1000000009 def main(): N,M = map(int,input().split()) S = [] RHS = [] for i in range(N): s = str(input()) S.append(s) temp = RollingHash(s,base1,mod1) RHS.append(temp.get(0,M)) ans = set([]) mae = S[0] for i in range(26): na = chr(i+97) + mae #print(na) frh = RollingHash(na[:-1],base1,mod1) first = frh.get(0,M) srh = RollingHash(na[1:],base1,mod1) second = srh.get(0,M) for j in range(1,N): if RHS[j] == first or RHS[j] == second: continue else: break else: ans.add(na) ato = S[0] for i in range(26): na = ato + chr(i+97) #print(na) frh = RollingHash(na[:-1],base1,mod1) first = frh.get(0,M) srh = RollingHash(na[1:],base1,mod1) second = srh.get(0,M) for j in range(1,N): #print(RHS[j],first,second) if RHS[j] == first or RHS[j] == second: continue else: break else: ans.add(na) print(len(ans)) if __name__ == '__main__': main()