unittest
{
	assert( [ "3 3", ".##", ".#.", "##." ].parse.expand.solve == 1 );
	assert( [ "2 2", "#.", ".#" ].parse.expand.solve == 2 );
	assert( [ "4 4", "..##", "#...", "###.", "###." ].parse.expand.solve == 0 );
	assert( [ "5 5", ".#.#.", "#.#.#", ".#.#.", "#.#.#", ".#.#." ].parse.expand.solve == 4 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto css = new dchar[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref cs; css )
	{
		input.popFront;
		cs = input.front.to!( dchar[] );
	}
	return tuple( css );
}

auto solve( dchar[][] css )
{
	auto dp = new long[][]( css.length, css[ 0 ].length );
	foreach( ref dpp; dp ) dpp[] = long.max;
	dp[ 0 ][ 0 ] = ( css[ 0 ][ 0 ] == '#' );
	foreach( y, cs; css )
	{
		foreach( x, c; cs )
		{
			auto pb = ( c == '#' );
			if( y + 1 < dp.length )
			{
				auto nb = ( css[ y + 1 ][ x ] == '#' );
				dp[ y + 1 ][ x ] = min( dp[ y + 1 ][ x ], dp[ y ][ x ] + ( !pb && nb ) );
			}
			if( x + 1 < dp[ y ].length )
			{
				auto nb = ( css[ y ][ x + 1 ] == '#' );
				dp[ y ][ x + 1 ] = min( dp[ y ][ x + 1 ], dp[ y ][ x ] + ( !pb && nb ) );
			}
		}
	}
	return dp[ $ - 1 ][ $ - 1 ];
}
