#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin.get(s[i][j]);
            if(s[i][j]=='\n'){
                cin.get(s[i][j]);

            }
        }
    }
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int c;
            c=((s[i][j]=='#')+(s[i+1][j]=='#')+(s[i][j+1]=='#')+(s[i+1][j+1]=='#'));
            if(c==1 || c==3){
                count++;
            }
        }
    }
    cout << count << endl;
}
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;

#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;

#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif

constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;

int
main()
{
    ios_base::sync_with_stdio(false);

    DRi64(R); DRi64(C);
    vec<string> G(R + 2, string(C + 2, '.'));
    for (i64 r = 1; r <= R; ++r)
    {
        DRS(S);
        for (i64 c = 0; c < C; ++c)
        {
            G[r][c + 1] = S[c];
        }
    }

    i64 horiz_sides = 0;
    for (i64 r = 1; r <= R + 1; ++r)
    {
        vec<i64> changes;
        for (i64 c = 1; c <= C; ++c)
        {
            let i64 diff = G[r - 1][c] != G[r][c];
            if (changes.empty())
            {
                if (diff == 1)
                {
                    changes.push_back(diff);
                }
            }
            else if (diff != changes.back())
            {
                changes.push_back(diff);
            }
        }
        horiz_sides += count(changes.begin(), changes.end(), 1);
    }
    i64 vert_sides = 0;
    for (i64 c = 1; c <= C + 1; ++c)
    {
        vec<i64> changes;
        for (i64 r = 1; r <= R; ++r)
        {
            let i64 diff = G[r][c - 1] != G[r][c];
            if (changes.empty())
            {
                if (diff == 1)
                {
                    changes.push_back(diff);
                }
            }
            else if (diff != changes.back())
            {
                changes.push_back(diff);
            }
        }
        vert_sides += count(changes.begin(), changes.end(), 1);
    }
    cout << horiz_sides + vert_sides << "\n";

    return 0;
}
