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

template <typename T>
inline bool chmax(T &current, const T &test){
  if (current < test){
    current = test;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T &current, const T &test){
  if (current > test){
    current = test;
    return true;
  }
  return false;
}

int corner_count(vector<vector<int>> &s, int i, int j){
  int sum = 0;
  sum += s[i][j] + s[i-1][j] + s[i][j-1] + s[i-1][j-1];
  if(sum == 1 || sum == 3){
    return 1;
  }else{
    return 0;
  }
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> s(h, vector<int> (w));
  char c;
  rep(i, h){
    rep(j, w){
      cin >> c;
      if(c =='#'){
        s[i][j] = 1;
      }else{
        s[i][j] = 0;
      }
    }
  }
  
  int ans = 0;
  
  for(int i = 1; i < h; i++){
    for(int j = 1; j < w; j++){
      ans += corner_count(s, i, j);
    }
  }
  
  cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int N=2e5+5;
int32_t main()
{
    int ans=0;
    int n;
    cin>>n;
    vector<vector<int>  > a(n,vector<int> (5));
    vector<vector<int>  > dp(5);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<5;j++)
        {
            cin>>a[i][j];
            dp[j].push_back(a[i][j]);
        }
    }
    for(int i=0;i<5;i++)
    {
        sort(begin(dp[i]),end(dp[i]),greater<int> ());
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int ind;
            int mini=1e9;
            for(int k=0;k<5;k++)
            {
                if(max(a[i][k],a[j][k])<mini)
                {
                    ind=k;
                    mini=max(a[i][k],a[j][k]);
                }
            }
            int val=1e9;
            for(int k=0;k<5;k++)
            {
                if(k!=ind)
                val=min(val,max(a[i][k],a[j][k]));
            }
            val=min(val,dp[ind][0]);
            ans=max(ans,val);
        }
    }
    cout<<ans<<endl;
}