#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int MOD = 1000000007;

/*
    実行時MODint :
    template <int& MOD = 1000000007>
    static int MOD;
    cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
    int x;

    constexpr Mint() : x(0) {}
    constexpr Mint(long long t)
        : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, p;
    cin >> n >> p;
    cout << Mint<>(p - 1) * Mint<>(p - 2).pow(n - 1) << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define ll long long
#define int long long
#define length size()
const int MOD = 1000000007;
const int MAX = 510000;
const int inf = 400000000000000;
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
bool isPrime(int n){
    //cout << n << endl;
    if(n == 1) return false;
    else if(n%2 == 0&&n!=2) return false;
    bool f = true;
    for(int i=3;i<=sqrt(n);i+=2){
        if(n%i==0){
            f = false;
            break;
        }
    }
    return f;
}
map<int,int> pf(int n){
    map<int,int> mp;
    if(n==1){
        mp[1] = 1;
        return mp;
    }else{
        int p = 2;
        while(n!=1){
            if(n%p==0){
                if(mp.find(p)==mp.end()){
                    mp[p] = 1;
                }else{
                    mp[p]++;
                }
                n /= p;
            }else{
                (p==2)?p++:p+=2;
            }
        }
        return mp;
    }
}
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
struct UnionFind{
    vector<int> par;
    vector<int> siz;
    int w;
    UnionFind(int n) : par(n),siz(n){
        for(int i=0;i<n;i++){par[i]=i;siz[i]=1;}
        w = n;
    }
    int root(int x){
        while(par[x]!=x){
            x = par[x] = par[par[x]];
        }
        return x;
    }
    void merge(int x,int y){
        x = root(x);
        y = root(y);
        if(siz[x]>siz[y]) swap(x,y);
        if(x!=y){
            siz[y] += siz[x];
            par[x] = y;
            w-=1;
        }
    }
    int size(int n){
        return siz[n];
    }
    int wid(){
        return w;
    }
};
vector<int> rev(vector<int> vec){
    rep(i,vec.size()){
        vec[i] = (vec[i]==1)?0:1;
    }
    return vec;
}
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
ll merge_cnt(vector<int> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<int> b(a.begin(), a.begin()+n/2);
    vector<int> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}
signed main(void){
    int h,w;
    cin >> h >> w;
    vector<vector<int>> vec(h+2,vector<int>(w+2,0));
    rep(i,h){
        rep(j,w){
            char t;
            cin >> t;
            if(t=='#'){
                vec[i+1][j+1] = 1;
            }
        }
    }
    int ans = 0;
    rep(i,h+1){
        rep(j,w+1){
            if(vec[i][j]+vec[i][j+1]+vec[i+1][j]+vec[i+1][j+1]==1||vec[i][j]+vec[i][j+1]+vec[i+1][j]+vec[i+1][j+1]==3) ans++;
        }
    }
    cout << ans << endl;
}