#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    // Failed to predict input format
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    int si, sj;
    bool last = false;
    int ans = 0;
    rep(i, H-1) rep(j, W-1) {
        bool cur = S[i][j] != S[i+1][j];
        if (cur && !last) ans++;
        last = cur;
    }
    last = false;
    rep(j, W-1) rep(i, H-1) {
        bool cur = S[i][j] != S[i][j+1];
        if (cur && !last) ans++;
        last = cur;
    }
    cout << ans << endl;

    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>

#define endl '\n'
#define sp ' '

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

string arr[15];
int h,w;
int kk=0;

int gez(int i, int j, int fi , int fj, int pos){//pos 1sag 2sol 3yukari 4 asagi
    int ret = 0;
    //cerr << i << sp << j << sp << pos << endl;
    if(i==fi && j==fj && pos == 3){
        if(kk)
            return ret;
        kk++;
    }   
    if(pos == 1){
        if(arr[i+1][j+1] == '#'){
            return 1 + gez(i+1,j+1,fi,fj,3);
        }
        if(arr[i+1][j] == '#'){
            return gez(i+1,j,fi,fj,1);
        }
        //if(arr[i][j-1] == '#'){
        //    return 1 + gez(i,j-1,fi,fj,4);
       // }
        return 1 + gez(i,j,fi,fj,4);
    }
    else if(pos == 2){
        if(arr[i-1][j-1] == '#'){
            return 1 + gez(i-1,j-1,fi,fj,4);
        }
        if(arr[i-1][j] == '#'){
            return gez(i-1,j,fi,fj,2);
        }
        //if(arr[i][j+1] == '#'){
       //     return 1 + gez(i,j,fi,fj,3);
       // }
        return 1 + gez(i,j,fi,fj,3);
    }
    else if(pos == 3){
        if(arr[i-1][j+1] == '#'){
            return 1 + gez(i-1,j+1,fi,fj,2);
        }
        if(arr[i][j+1] == '#'){
            return gez(i,j+1,fi,fj,3);
        }
       // if(arr[i+1][j] == '#'){
       //     return 1+gez(i,j,fi,fj,1);
       // }
        return 1 + gez(i,j,fi,fj,1);
    }
    else{ // pos == 4
        if(arr[i+1][j-1] == '#'){
            return 1 + gez(i+1,j-1,fi,fj,1);
        }
        if(arr[i][j-1] == '#'){
            return gez(i,j-1,fi,fj,4);
        }
       // if(arr[i-1][j] == '#'){
       //     return 1+gez(i,j,fi,fj,2);
      //  }
        return 1 + gez(i,j,fi,fj,2);
    }
    
}

int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    cin>>h>>w;

    for(int i=0;i<h;i++)
        cin>>arr[i];

    int fi=-1, fj=-1;
    bool flag = false;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(arr[i][j] == '#'){
                fi = i;
                fj = j;
                flag = true;
                break;
            }
        }
        if(flag)
            break;
    }
    
    if(fi == -1 && fj == -1){
        cout << 0 << endl;
        exit(0);
    }
    //cerr << fi << sp << fj << endl; 
    cout << gez(fi,fj,fi,fj,3) << endl;
    
}











