#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int H; cin>>H;
    int W; cin>>W;
    vector<string> S(H); rep(i,H)cin>>S.at(i);

    int ans = 0;

    for(int i=1;i<H;i++){
        for(int j=1; j<W;j++ ){
            if((S.at(i).at(j)=='#'&&S.at(i).at(j-1)=='.')){
                if(!(S.at(i-1).at(j)=='#'&&S.at(i-1).at(j-1)=='.')){
                    ans++;
                }
            }
            if((S.at(i).at(j)=='.'&&S.at(i).at(j-1)=='#')){
                if(!(S.at(i-1).at(j)=='.'&&S.at(i-1).at(j-1)=='#')){
                // if(S.at(i-1).at(j-1)=='#'){
                    ans++;
                }
            }
        }
    }

    for(int j=1; j<W;j++ ){
        for(int i=1;i<H;i++){
            if((S.at(i).at(j)=='#'&&S.at(i-1).at(j)=='.')){
                if(!(S.at(i).at(j-1)=='#'&&S.at(i-1).at(j-1)=='.')){
                    ans++;
                }
            }
            if((S.at(i).at(j)=='.'&&S.at(i-1).at(j)=='#')){
                if(!(S.at(i).at(j-1)=='.'&&S.at(i-1).at(j-1)=='#')){
                    ans++;
                }
            }
        }
    }


    cout<<ans<<endl;






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

#define ll long long
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define P pair<ll, ll>

int main(){
    ll K;
    cin >> K;

    string S, T;
    cin >> S >> T;

    vector<ll> card(9);
    vector<ll> a_hand(9), t_hand(9);
    rep(i, 9) card.at(i) = K;
    rep(i, 4){
        card.at(S[i]-'0'-1)--;
        t_hand.at(S[i]-'0'-1)++;
        card.at(T[i]-'0'-1)--;
        a_hand.at(T[i]-'0'-1)++;
    }

    vector<P> conbi;

    for(ll a=1; a<=9; a++){
        if(card.at(a-1) == 0) continue;

        ll a_score = 0;
        card.at(a-1)--;
        a_hand.at(a-1)++;
        rep(i, 9) a_score += (i+1)*pow(10, a_hand.at(i));

        for(ll t=1; t<=9; t++){
            if(card.at(t-1) == 0) continue;

            ll t_score = 0;
            t_hand.at(t-1)++;
            rep(i, 9) t_score += (i+1)*pow(10, t_hand.at(i));

            //cout << "a_score:" << a_score << ", t_score:" << t_score << endl;

            if(a_score < t_score) conbi.push_back(make_pair(a, t));

            t_hand.at(t-1)--;
        }

        a_hand.at(a-1)--;
        card.at(a-1)++;
    }

    double ans = 0;
    for(ll i=0; i<conbi.size(); i++){
        double first_p = (double)card.at(conbi.at(i).first-1)/(9*(double)K-8);
        card.at(conbi.at(i).first-1)--;
        double second_p = (double)card.at(conbi.at(i).second-1)/(9*(double)K-9);
        ans += first_p*second_p;
        card.at(conbi.at(i).first-1)++;
    }

    cout << fixed << setprecision(10) << ans << endl;
}