import sys sys.setrecursionlimit(10 ** 9) n, m = map(int, input().split()) lst = [input() for _ in range(n)] S = lst[0] T = lst[1] tmp = [] ans = 0 def ok(): for S in lst: p = 0 for t in tmp: if S[p] == t: p += 1 if p == m: break if p != m: return False return True def dfs(sp, tp, x): if sp == m and tp == m: global ans if ok(): ans += 1 return if sp < m and tp < m and S[sp] == T[tp]: tmp.append(S[sp]) dfs(sp + 1, tp + 1, x) tmp.pop() else: if sp < m and not x & 1: tmp.append(S[sp]) dfs(sp + 1, tp, x ^ 1) tmp.pop() if tp < m and not x & 2: tmp.append(T[tp]) dfs(sp, tp + 1, x ^ 2) tmp.pop() dfs(0, 0, 0) print(ans)