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 diff_at = (0..m).filter(|&i| words[0][i] != words[1][i]).nth(0).unwrap(); let t1 = format!("{}{}{}", (0..diff_at).map(|i| words[0][i].to_string()).collect::>().join(""), words[0][diff_at], (diff_at..m).map(|i| words[1][i].to_string()).collect::>().join("") ) .chars() .collect::>(); let t2 = format!("{}{}{}", (0..diff_at).map(|i| words[0][i].to_string()).collect::>().join(""), words[1][diff_at], (diff_at..m).map(|i| words[0][i].to_string()).collect::>().join("") ) .chars() .collect::>(); let ok = |word: &Vec, t: &Vec| -> bool { let m = word.len(); let diff_at = (0..=m).filter(|&i| i == m || word[i] != t[i]).nth(0).unwrap(); if diff_at == m { return true; } (diff_at..m).map(|i| word[i] == t[i+1]).fold(true, |x, y| x && y) }; let mut result = 0usize; if (0..n).filter(|&i| !ok(&words[i], &t1)).count() == 0 { result += 1; } if (0..n).filter(|&i| !ok(&words[i], &t2)).count() == 0 { result += 1; } println!("{}", result); }