fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let m = nm[1]; let words = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.chars().collect::>() }) .collect::>(); let s1 = &words[0]; let s2 = &words[1]; let front_same_cnt = (0..m).filter(|&i| s1[i] != s2[i]).nth(0).unwrap(); let back_diff_point = (0..m).rev().filter(|&i| s1[i] != s2[i]).nth(0).unwrap(); let t1 = format!("{}{}{}{}", (0..front_same_cnt).map(|i| s1[i].to_string()).collect::>().join(""), (front_same_cnt..=back_diff_point).map(|i| s1[i].to_string()).collect::>().join(""), s2[back_diff_point], (back_diff_point+1..m).map(|i| s1[i].to_string()).collect::>().join("") ).chars().collect::>(); let t2 = format!("{}{}{}{}", (0..front_same_cnt).map(|i| s2[i].to_string()).collect::>().join(""), (front_same_cnt..=back_diff_point).map(|i| s2[i].to_string()).collect::>().join(""), s1[back_diff_point], (back_diff_point+1..m).map(|i| s2[i].to_string()).collect::>().join("") ).chars().collect::>(); let is_ok = |s: &Vec, t: &Vec| { let front_same_cnt = (0..m+1).filter(|&i| i == m || s[i] != t[i]).nth(0).unwrap(); (front_same_cnt..s.len()).filter(|&i| s[i] != t[i+1]).count() == 0 }; let mut result = 0; if (0..n).map(|i| is_ok(&words[i], &t1)).fold(true, |x, y| x && y) { result += 1; } if (0..n).map(|i| is_ok(&words[i], &t2)).fold(true, |x, y| x && y) { result += 1; } println!("{}", result); }