use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let h: usize = it.next().unwrap().parse().unwrap(); let w: usize = it.next().unwrap().parse().unwrap(); let s: Vec> = it.map(|s| s.chars().collect()).collect(); let mut dp = vec![vec![std::usize::MAX / 2; w]; h]; dp[0][0] = 0; for i in 0..h { for j in 0..w { let cost = if s[i][j] == '.' {1} else {1 + i + j}; if i > 0 { dp[i][j] = std::cmp::min(dp[i][j], dp[i - 1][j] + cost); } if j > 0 { dp[i][j] = std::cmp::min(dp[i][j], dp[i][j - 1] + cost); } } } let ans = dp[h - 1][w - 1]; println!("{}", ans); } fn main() { run(); }