#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(), c.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a; i <= b; ++i)
#define rep3(i, a, b) for (int i = a; i >= b; --i)
#define endl '\n'
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }

template <class T, class S>
inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S>
inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
#define INT(...)     \
    int __VA_ARGS__; \
    IN(__VA_ARGS__)
#define LL(...)     \
    ll __VA_ARGS__; \
    IN(__VA_ARGS__)
#define VEC(type, name, size) \
    vector<type> name(size);  \
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                       \
    vector<vector<type>> name(h, vector<type>(w)); \
    IN(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S>
void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T>
void scan(vector<T> &);
template <class T>
void scan(vector<T> &a) {
    for (auto &i : a)
        scan(i);
}
template <class T>
void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail>
void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}
template <class T>
vector<T> divisor(T x) {
    vector<T> ans;
    for (T i = 1; i * i <= x; i++)
        if (x % i == 0) {
            ans.pb(i);
            if (i * i != x)
                ans.pb(x / i);
        }
    return ans;
}
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// constexpr int inf = 1e9;
// constexpr i64 inf = 1e18;
// const int N = 500 * 1000 + 5; // use for N <= 5 * 10^5
// const int MX = 1e9 + 7; // For convenience, find the answer modulo 10^9+7
// cout << rng();
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    INT(h, w);
    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }
    int ans = 0;
    rep2(i, 1, h - 2) {
        rep2(j, 1, w - 2) {
            if (s[i][j] == '#') {
                // for R and L
                if (s[i][j - 1] == '.') {
                    ans += 1;
                    if (s[i - 1][j] == '#' and s[i - 1][j - 1] == '.') {
                        ans -= 1;
                    }
                }
                if (s[i][j + 1] == '.') {
                    ans += 1;
                    if (s[i - 1][j] == '#' and s[i - 1][j + 1] == '.') {
                        ans -= 1;
                    }
                }
                if (s[i - 1][j] == '.') {
                    ans += 1;
                    if (s[i][j - 1] == '#' and s[i - 1][j - 1] == '.') {
                        ans -= 1;
                    }
                }
                if (s[i + 1][j] == '.') {
                    ans += 1;
                    if (s[i][j - 1] == '#' and s[i + 1][j - 1] == '.') {
                        ans -= 1;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for(int i = 0; i < v.size(); ++i) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}


void solve() {

	ll H, W;
    cin >> H >> W;

    vector<string> grid(H);

    for(string &row: grid) {
        cin >> row;
    }

    vector<vector<char>> c = vector<vector<char>>(H, vector<char>(W, '.'));

    ll ans = 0;

    for(ll i = 0; i < H - 1; ++i) {
        for(ll j = 0; j < W - 1; ++j) {
            ll count = 0;
            if(grid[i][j] == grid[i+1][j]) count++;
            if(grid[i][j] == grid[i][j+1]) count++;
            if(grid[i][j] == grid[i+1][j+1]) count++;

            if(count == 0 || count == 2) {
                ans++;
                c[i][j] = 'C';
            }

        }
    }


    // for(auto r: c) {
    //     for(char x: r) cout << x << "";
    //     cout << "\n";
    // } 

    cout << ans;
}

signed main() {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	//cin >> t;

	while(t--) 
		solve();

	return 0;
}


