package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	H, W := sc.nextInt(), sc.nextInt()
	G := make([][]rune, H)
	// D[i][j]: i,j地点への最小手数
	D := make([][]int, H)
	Id := make([][]int, H)
	for i := 0; i < H; i++ {
		G[i] = sc.nextRuneSlice()
		D[i] = make([]int, W)
		Id[i] = make([]int, W)
		for j := 0; j < W; j++ {
			D[i][j] = INF
		}
	}
	dw := []int{0, 1}
	dh := []int{1, 0}
	queue := Queue{}
	bfs := func(cur Node) {
		w, h := cur.w, cur.h
		for i := 0; i < 2; i++ {
			nw, nh := w+dw[i], h+dh[i]
			if nw >= W || nh >= H {
				continue
			}
			var nextCost int
			if (G[h][w] == '#' && G[nh][nw] == '.') || (nh == H-1 && nw == W-1 && G[nh][nw] == '#') {
				nextCost = D[h][w] + 1
			} else {
				nextCost = D[h][w]
			}
			if nextCost < D[nh][nw] {
				D[nh][nw] = nextCost
				queue.push(Node{nh, nw, Id[nh][nw]})
				Id[nh][nw]++
			}
		}
	}
	D[0][0] = 0
	queue.push(Node{0, 0, Id[0][0]})
	Id[0][0]++
	for !queue.isEmpty() {
		node := queue.pop()
		//h, w := node.h, node.w
		//fmt.Fprintln(wtr, node, D[h][w], Id[h][w])
		if node.id == Id[node.h][node.w]-1 {
			bfs(node)
		}
	}

	fmt.Fprintln(wtr, D[H-1][W-1])
}

type Node struct {
	h, w, id int
}

type Queue struct {
	arr []Node
}

func (q *Queue) push(v Node) {
	q.arr = append(q.arr, v)
}

func (q *Queue) pop() Node {
	res := q.arr[0]
	q.arr = q.arr[1:]
	return res
}

func (q *Queue) isEmpty() bool {
	return len(q.arr) == 0
}


Measured memory_bytes: 1536