#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
struct BFS01 {
    struct edge {
        ll to, cost;
    };
    typedef pair<ll, ll> P;//firstは最短距離、secondは頂点の番号

    int V;//超点数
    vector<vector<edge> > G;//グラフ,G[i]はiから出る辺の集合,G[i][j]はiから出る辺のj番目の辺
    vector<ll> d; //最短距離

    BFS01(int N) {
        V = N;
        G.resize(N);
        d = vector<ll>(N);
    };

    void addEdge(int from, int to, int cost) {
        edge e;
        e.to = to;
        e.cost = cost;
        G[from].push_back(e);
    }

    void calc(int s) {
//        priority_queue<P,vector<P>,greater<P> > que;
        deque<P> que;
        fill(d.begin(), d.end(), INFl);
        d[s] = 0;
        que.push_back(P(0, s));

        while (!que.empty()) {
            P p = que.front();
            que.pop_front();
            ll v = p.second;
            if (d[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost && !(d[e.to] == INFl && d[v] == INFl)) {
                    d[e.to] = d[v] + e.cost;
                    if (e.cost == 0) {
                        que.push_front(P(d[e.to], e.to));
                    } else {
                        que.push_back(P(d[e.to], e.to));
                    }
                }
            }
        }

    }
};


class Solve {
public:
    void solve() {
        Int H, W;
        cin >> H >> W;
        vector<string> S(H);
        for (int i = 0; i < H; ++i) {
            cin >> S[i];
        }


        auto conv = [&](int h, int w) {
            return h * W + w;
        };

        //境目の数で実装してみる

        BFS01 bfs(H * W);
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
//                vector<Int> dh = {0, 1, 0, -1};
//                vector<Int> dw = {-1, 0, 1, 0};
                vector<Int> dh = {0, 1};
                vector<Int> dw = {1, 0};

                for (int k = 0; k < 2; ++k) {
                    int h = i + dh[k];
                    int w = j + dw[k];
                    if (h >= 0 && h < H && w >= 0 && w < W) {
//                        if(S[h][w] == S[i][j])
                        Int from = conv(i, j);
                        Int to = conv(h, w);
                        bfs.addEdge(from, to, S[h][w] != S[i][j]);
//                        bfs.addEdge(to, from, S[h][w] != S[i][j]);
                    }

                }
            }
        }

        bfs.calc(conv(0, 0));
        Int dist = bfs.d[conv(H - 1, W - 1)];
        Int ans = -1;
        if (S[0][0] != S[H - 1][W - 1]) {
            ans = (dist + 1) / 2;
        } else if (S[0][0] == '#') {
            ans = dist / 2 + 1;
        } else {
            ans = dist / 2;
        }

        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1024