#include <bits/stdc++.h>
using namespace std;
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
 
int main(){
  int h,w; cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  int ans=0;
  rep(i,h){
    rep(j,w-1){
      if(s[i][j]=='.' && s[i][j+1]=='.') ans++;
    }
  }

  rep(i,w){
    rep(j,h-1){
      if(s[j+1][i]=='.' && s[j][i]=='.') ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    const int INF = 1001001001;
    vector<vector<int>> dp(1100, vector<int>(1100, INF));

    rep(i, n) dp[i][0] = i;
    rep(j, m) dp[0][j] = j;

    rep1(i, n+1) rep1(j, m+1){
        int cost = 1;
        if(a[i-1] == b[j-1]) cost = 0;
        dp[i][j] = min({dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+cost});
    }

    cout << dp[n][m] << endl;

    return 0;
}