package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func isGood(s [100][100]byte, h, w int) bool {
	var tmp1 [100][2]int
	count1 := 0
	var tmp2 [100][2]int
	count2 := 0

	// first round
	if s[0][0] == 46 {
		tmp1[0][0] = 1
		tmp1[0][1] = 0
		tmp1[1][0] = 0
		tmp1[1][1] = 1
		count1 += 2
	} else {
		return false
	}

	for {
		if count1 == 0 {
			break
		}
		// even round
		for i := 0; i < count1; i++ {
			if tmp1[i][0] == h-1 && tmp1[i][1] == w-1 {
				return true
			}
			if tmp1[i][0] == h || tmp1[i][1] == w {
				continue
			}
			if s[tmp1[i][0]][tmp1[i][1]] == 46 { // white
				tmp2[count2][0] = tmp1[i][0] + 1
				tmp2[count2][1] = tmp1[i][1]
				tmp2[count2+1][0] = tmp1[i][0]
				tmp2[count2+1][1] = tmp1[i][1] + 1
				count2 += 2
			}
		}
		// fmt.Printf("%v\n", tmp2[0:5])
		count1 = 0

		if count2 == 0 {
			break
		}
		// odd round
		for i := 0; i < count2; i++ {
			if tmp2[i][0] == h-1 && tmp2[i][1] == w-1 {
				return true
			}
			if tmp2[i][0] == h || tmp2[i][1] == w {
				continue
			}
			if s[tmp2[i][0]][tmp2[i][1]] == 46 { // white
				tmp1[count1][0] = tmp2[i][0] + 1
				tmp1[count1][1] = tmp2[i][1]
				tmp1[count1+1][0] = tmp2[i][0]
				tmp1[count1+1][1] = tmp2[i][1] + 1
				count1 += 2
			}
		}
		// fmt.Printf("%v\n", tmp1[0:5])
		count2 = 0
	}
	return false
}

func countbubble(s [100][100]byte, h, w int) int {
	var bubbles [100][100]int

	// round 0
	bubbles[0][0] = 0

	// fmt.Printf("%d, %d\n", h, w)
	// round >= 1
	for r := 1; r < h+w-1; r++ {
		for p := 0; p < r+1; p++ {
			rt := r - p
			ct := p
			if rt < 0 || rt >= h || ct < 0 || ct >= w {
				continue
			}
			// fmt.Printf("r%d, rt%d, ct%d\n", r, rt, ct)

			if rt == 0 {
				if s[rt][ct-1] == s[rt][ct] {
					bubbles[rt][ct] = bubbles[rt][ct-1]
				} else {
					bubbles[rt][ct] = bubbles[rt][ct-1] + 1
				}
			} else if ct == 0 {
				if s[rt-1][ct] == s[rt][ct] {
					bubbles[rt][ct] = bubbles[rt-1][ct]
				} else {
					bubbles[rt][ct] = bubbles[rt-1][ct] + 1
				}
			} else {
				bubbleFromLeft := 0
				bubbleFromUp := 0
				if s[rt][ct-1] == s[rt][ct] {
					bubbleFromLeft = bubbles[rt][ct-1]
				} else {
					bubbleFromLeft = bubbles[rt][ct-1] + 1
				}
				if s[rt-1][ct] == s[rt][ct] {
					bubbleFromUp = bubbles[rt-1][ct]
				} else {
					bubbleFromUp = bubbles[rt-1][ct] + 1
				}
				if bubbleFromLeft > bubbleFromUp {
					bubbles[rt][ct] = bubbleFromUp
				} else {
					bubbles[rt][ct] = bubbleFromLeft
				}
			}
		}
	}
	// for i := 0; i < h; i++ {
	// 	fmt.Printf("%v\n", bubbles[i][0:w])
	// }
	candidate := bubbles[h-1][w-1]
	if s[0][0] == 46 && s[h-1][w-1] == 46 {
		return candidate / 2
	} else if s[0][0] == 35 && s[h-1][w-1] == 35 {
		return candidate/2 + 1
	} else {
		return (candidate + 1) / 2
	}
}

func main() {
	io := NewIo()
	defer io.Flush()
	H := io.NextInt()
	W := io.NextInt()
	// fmt.Printf("%d, %d\n", H, W)
	var s [100][100]byte

	for i := 0; i < H; i++ {
		str := io.Next()
		for j := 0; j < W; j++ {
			s[i][j] = str[j]
		}
	}
	// fmt.Printf("%v %v\n", s[0][0], s[0][0] == 35) // #
	// fmt.Printf("%v %v\n", s[0][1], s[0][1] == 46) // .
	// fmt.Printf("%v\n", isGood(s, H, W))
	fmt.Printf("%v\n", countbubble(s, H, W))
	// fmt.Printf("%v\n", s)
}


Measured memory_bytes: 768