#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn get_index(x: usize, y: usize, w: usize) -> usize {
    y * w + x
}

fn get_adjacents(x: usize, y: usize, w: usize, h: usize) -> Vec<(usize, usize)> {
    let mut adjacents = vec![];
    if x > 0 {
        adjacents.push((x - 1, y));
    }
    if y > 0 {
        adjacents.push((x, y - 1));
    }
    adjacents.push((x, y));
    if y < h - 1 {
        adjacents.push((x, y + 1));
    }
    if x < w - 1 {
        adjacents.push((x + 1, y));
    }
    adjacents
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);

    let mut grid = vec![vec![]; h];
    for y in 0..h {
        grid[y] = read::<String>().chars().collect::<Vec<_>>();
    }

    let mut dp = vec![vec![std::i64::MAX; w]; h];
    if grid[0][0] == '#' {
        dp[0][0] = 1;
    } else {
        dp[0][0] = 0;
    }
    for y in 0..h {
        for x in 0..w {
            let mut adj = vec![];
            if x > 0 {
                adj.push((x - 1, y));
            }
            if y > 0 {
                adj.push((x, y - 1));
            }
            for (adj_x, adj_y) in adj {
                if grid[y][x] == grid[adj_y][adj_x] {
                    dp[y][x] = min(dp[y][x], dp[adj_y][adj_x]);
                } else if grid[y][x] == '#' {
                    dp[y][x] = min(dp[y][x], dp[adj_y][adj_x] + 1);
                } else {
                    dp[y][x] = min(dp[y][x], dp[adj_y][adj_x]);
                }
            }
        }
    }
    println!("{}", dp[h - 1][w - 1]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

use std::cmp::Ordering;
use std::collections::BinaryHeap;
const INF: i64 = 100000_00000_00000;

#[derive(PartialEq, Debug)]
struct MinInt {
    value: i64,
}

impl Eq for MinInt {}

impl PartialOrd for MinInt {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        other.value.partial_cmp(&self.value)
    }
}

impl Ord for MinInt {
    fn cmp(&self, other: &MinInt) -> Ordering {
        other.value.cmp(&self.value)
    }
}

fn make_pair(x: i64, y: usize) -> (MinInt, usize) {
    (MinInt { value: x }, y)
}

#[derive(Debug, Clone)]
struct Edge {
    to: usize,
    cost: i64,
}

fn solve(edges: &Vec<Vec<Edge>>, start_idx: usize) -> Vec<i64> {
    let num_apexes = edges.len();
    let mut d = vec![INF; num_apexes];
    d[start_idx] = 0;
    let mut que = BinaryHeap::new();
    que.push(make_pair(0, start_idx));

    while let Some((u, v)) = que.pop() {
        if d[v] < u.value {
            continue;
        }
        for e in &edges[v] {
            if d[v] != INF && d[e.to] > d[v] + e.cost {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    d
}


Measured memory_bytes: 4352