#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//組み合わせ計算
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

//繰り返し二乗法
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}



int main(){
    ll h,w;
    cin >> h >> w;
    char grid[2005][2005];
    rep(i,h)rep(j,w){
        cin >> grid[i][j];
    }
    
    mint kazu[2005][2005];
    rep(i,h){
        rep(j,w){
            kazu[i][j]=0;
        }
    }
    
    kazu[0][0]=1;
    mint houkou[2005][2005][3];
    
    rep(i,h){
        rep(j,w){
            rep(k,3){
                houkou[i][j][k]=0;
            }
        }
    }
    
    houkou[0][0][0]=0;
    houkou[0][0][1]=0;
    houkou[0][0][2]=0;
    
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(i!=0||j!=0){
                if(grid[i][j]=='.'){
                    kazu[i][j]=houkou[i][j][0]+houkou[i][j][1]+houkou[i][j][2];
                }
            }
            if(grid[i][j]=='#') continue;
            houkou[i+1][j][0]=houkou[i][j][0]+kazu[i][j];
            houkou[i+1][j+1][1]=houkou[i][j][1]+kazu[i][j];
            houkou[i][j+1][2]=houkou[i][j][2]+kazu[i][j];
        }
    }
    
    cout << kazu[h-1][w-1] << endl;
    
    

    return 0;
}










#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define int long long 
#define ll int
#define ull unsigned long long
#define all(a) a.begin(),a.end()	
#define rev(a) a.rbegin(),a.rend()	
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);

int x,y;
map<int,int> mapka;
int rec(int val)
{
	if(mapka.find(val)!=mapka.end()) return mapka[val];
	if(val<=x)
	{
		return mapka[val]=x-val;
	}
	mapka[val]=val-x;
	if(val%2==0)
	{
		mapka[val]=min(mapka[val],1+rec(val/2));
	}
	else
	{
		mapka[val]=min({mapka[val],2+rec((val+1)/2),2+rec((val-1)/2)});
	}
	return mapka[val];

}

void solve()
{
	cin>>x>>y;
	if(x>=y)
	{
		cout<<x-y<<'\n';
		return ;
	}
	cout<<rec(y);
	
	
}

signed main()
{
	FAST;
	int tt=1;
	// cin>>tt;	
	while(tt--)
	{
		solve();
	}	
}
