#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

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){
    if (s[i][j] == '#') continue;
    if (j+1 < w) if (s[i][j+1] == '.') ans++;
    if (i+1 < h) if (s[i+1][j] == '.') ans++;
  }
  cout << ans << endl;
  
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll
 
map<ll,ll> visits;
ll x,y,ans=inff;

void solve(ll y,ll cnt){
	queue<ll> q;
	q.push(y);
	visits[y]=1;
	while (!q.empty()){
		ll now=q.front(); q.pop();
		ans=min(ans,abs(x-now)+visits[now]-1);
		if (now&1){
			if (!visits[now+1]) visits[now+1]=visits[now]+1,q.push(now+1);
			if (!visits[now-1]) visits[now-1]=visits[now]+1,q.push(now-1);
		}
		else{
			if (!visits[now>>1]) visits[now>>1]=visits[now]+1,q.push(now>>1);
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>x>>y;
	solve(y,0);
	cout<<ans<<'\n';
}
