#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << x;
#define OUTL(x) cout << x << endl;
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

int mins(ll a, ll b)
{
    if (a == 0 && b == 0) return 0;
    if (a == b || a == -b) return 1;
    if (abs(a) + abs(b) <= 3) return 1;
    if (abs(a - b) <= 3 || abs(a + b) <= 3) return 2;
    if (abs(a) + abs(b) <= 6) return 2;
    if ((a + b) % 2 == 0) return 2;
    return 3;
}

void solve()
{
    IN(a, b, c, d);
    OUTL(mins(c-a, d-b));
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1;
 //cin>>t;
 while(t--)
 {int n,m;
  cin>>n>>m;
  vector<string> v(n);
  rep(i,0,n){
    cin>>v[i];
  }
  int ans=0;
  rep(i,1,n){
    rep(j,0,m){
        int f=0;
        while(v[i][j]=='#'&&v[i-1][j]=='.'){
            f=1;
            j++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(i,0,n-1){
    rep(j,0,m){
        int f=0;
        while(v[i][j]=='#'&&v[i+1][j]=='.'){
            f=1;
            j++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(j,1,m){
    rep(i,0,n){
        int f=0;
        while(v[i][j]=='#'&&v[i][j-1]=='.'){
            f=1;
            i++;
        }
        if(f){
            ans++;
        }
    }
  }
  rep(j,0,m-1){
    rep(i,0,n){
        int f=0;
        while(v[i][j]=='#'&&v[i][j+1]=='.'){
            f=1;
            i++;
        }
        if(f){
            ans++;
        }
    }
  }
  cout<<ans<<endl;
 }
 return 0;
}
