using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static char[][] bm;
	static int[][] b;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int h=s[0],w=s[1];
		char c='#';
		bm=new char[h+2][];
		b=new int[h+2][];
		var dp=new int[h+2][];
		for(int i = 1;i<=h;i++) {
			bm[i]=(c+sc.S+c).ToCharArray();
			b[i]=Enumerable.Repeat(10000,w+2).ToArray();
		}
		bm[0]=bm[h+1]=new string(c,w+2).ToCharArray();
		var qu=new Qu2<Tuple<int,int>>();
		qu.Enqueue0(0,Tuple.Create(1,1));
		b[1][1]=1;
		int ans=0;
		while(qu.cnt>0){
			var e=qu.Dequeue;
			if(b[e.d.Item1][e.d.Item2]==-1){continue;}
			b[e.d.Item1][e.d.Item2]=-1;
			if(e.d.Item1==h&&e.d.Item2==w){
				ans=e.n/2;
				break;
			}
			if(e.d.Item1!=h&&b[e.d.Item1+1][e.d.Item2]>e.n){
				qu.Enqueue(bm[e.d.Item1][e.d.Item2]==bm[e.d.Item1+1][e.d.Item2],e.n,Tuple.Create(e.d.Item1+1,e.d.Item2));
				b[e.d.Item1+1][e.d.Item2]=e.n;
			}
			if(e.d.Item2!=w&&b[e.d.Item1][e.d.Item2+1]>e.n){
				qu.Enqueue(bm[e.d.Item1][e.d.Item2]==bm[e.d.Item1][e.d.Item2+1],e.n,Tuple.Create(e.d.Item1,e.d.Item2+1));
				b[e.d.Item1][e.d.Item2+1]=e.n;
			}
		}
		if(bm[1][1]==c||bm[h][w]==c){ans++;}
		Console.WriteLine("{0}",ans);
	}
}
public class Qu2<T>{
	public class Dt{
		public int n;
		public T d;
		public Dt(int n,T d){this.n=n;this.d=d;}
		public override string ToString()=>"n:"+n.ToString()+" d:"+d.ToString();
	}
	private Queue<Dt> qu0=new Queue<Dt>(),qu1=new Queue<Dt>();
	public void Enqueue(bool b,int n,T d){
		if(b){qu0.Enqueue(new Dt(n,d));}
		else{qu1.Enqueue(new Dt(n+1,d));}
	}
	public void Enqueue0(int n,T d){qu0.Enqueue(new Dt(n,d));}
	public void Enqueue1(int n,T d){qu1.Enqueue(new Dt(n,d));}
	public Dt Dequeue{get{return qu0.Count>0?qu0.Dequeue():qu1.Dequeue();}}
	public Dt Peek{get{return qu0.Count>0?qu0.Peek():qu1.Peek();}}
	public int cnt{get{return qu0.Count+qu1.Count;}}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13524