using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var s = SList(n); var pt = 0; for (var i = 0; i < m; ++i) { if (s[0][i] != s[1][i]) { pt = i; break; } } var ans = 0; var t1 = s[0].ToList(); t1.Insert(pt, s[1][pt]); var flg = true; foreach (var si in s) { if (!Check(t1, si)) { flg = false; break; } } if (flg) ++ans; var t2 = s[1].ToList(); t2.Insert(pt, s[0][pt]); flg = true; foreach (var si in s) { if (!Check(t2, si)) { flg = false; break; } } if (flg) ++ans; WriteLine(ans); } static bool Check(List t, string s) { var pos = 0; for (var i = 0; i < t.Count; ++i) { if (pos < s.Length && t[i] == s[pos]) ++pos; } return pos == s.Length; } }