
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int h,w;
        cin>>h>>w;
        int arr[h*w+10];
        int mn=mod;ll sum=0;
        for(int i=0;i<h*w;i++)
        {
            cin>>arr[i];
            mn=min(mn,arr[i]);
        }
        // cout<<mn<<" ";
        for(int i=0;i<h*w;i++)
        {
            sum+=arr[i]-mn;
            // cout<<arr[i]<<" ";
        }
        cout<<sum;
       
        return 0;
    }

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define free(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define bs binary_search
#define le length()
#define np(s) next_permutation(s.begin(),s.end())
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define unq(v) v.erase(unique(v.begin(),v.end()),v.end())
//1 1 1 2 2 2 to 1 2
const ll max_i=1e18+7;
const int dx[]={1,0,-1,0,-1,1,1,-1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const char dir[]={'R','D','L','U'};
const ll mod=1e12+7;
const ll N=1e5+1;


void solve()
{
	int n,m;
	cin>>n>>m;
	char arr[n][m];
	forn(i,n)
	forn(j,m)
	cin>>arr[i][j];
	//up
	ll ans=0;
	forn(i,m){
	forn(j,n)
	{
		 if(arr[j][i]=='#') 
		  {
			if(arr[j-1][i]=='.' && !(arr[j-1][i+1]=='.' && arr[j][i+1]== '#'))
			{
				ans++;
			}
		  }
	}
   }
   //cout<<ans<<"\n";
	//down
	forn(i,m)
	for(int j=n-1;j>=0;j--)
	{
		  if(arr[j][i]=='#') 
		  {
			if(arr[j+1][i]=='.' && !(arr[j+1][i+1]=='.' && arr[j][i+1]== '#'))
			{
				ans++;
			}
		  }
	}
	//cout<<ans<<"\n";
	//left
	forn(i,n)
	forn(j,m)
	{
		 if(arr[i][j]=='#') 
		  {
			if(arr[i][j-1]=='.' && !(arr[i-1][j-1]=='.' && arr[i-1][j]== '#'))
			{
				ans++;
			}
		  }
	}
	//cout<<ans<<"\n";
	//right
	forn(i,n){
	for(int j=m-1;j>=0;j--)
	{
		if(arr[i][j]=='#') 
		  {
			if(arr[i][j+1]=='.' && !(arr[i-1][j+1]=='.' && arr[i-1][j]== '#'))
			{
				ans++;
			}
		  }
	}
}
  cout<<ans<<"\n";
}

int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input1.txt", "r",stdin);
  freopen("output1.txt","w",stdout);
  #endif
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

  int t=1;
  //cin>>t;
  while(t--) solve();
  return 0;
}
//unordered_map
//unordered_set
//find
//insert
//cout<<fixed<<setprecision(9)<<x;