#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vl;
typedef vector<pii> vpii; typedef vector<pll> vpll;
#define FOR(n) for(int i=0;i<n;++i)
#define FOR1(n) for(int i=1;i<=n;++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; }
const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f;
ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; }
void re(vi& a) { for (auto& t : a)cin >> t; }void re(vl& a) { for (auto& t : a)cin >> t; }
void pr(vi& a) { for (auto& t : a)cout << t << " "; cout << endl; }
void pr(vl& a) { for (auto& t : a)cout << t << " "; cout << endl; }

signed main() {
	int n;
	cin >> n;
	vi a(n), b(n);
	FOR(n)cin >> a[i] >> b[i];
	int ans = inf;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j)ans = min(ans, max(a[i], b[j]));
			else ans = min(ans, a[i] + b[j]);
		}
	}
	cout << ans;
}
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int N = 2441;

using namespace std;
int  n , m , value; 
ll a[ N ][ N ] , ro[ N ] , col[ N ] , mod = 1e9+7 ;

map <ll,ll> dia;

char ch;

int main(){
fcin;
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++) {
		for(int j = 0 ; j < m ; j++) {
			cin >> ch;
			a[i][j] = (ch == '.');
		}
	}

	ll ans = 0;

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			
			if(!a[i][j]) {
				dia[i-j] = 0;
				ro[i] = 0;
				col[j] = 0;
				continue;
			}
			if(!i && !j) {
				dia[0] = 1;
				col[j] = 1;
				ro[i] = 1;
			}	
			else {
				value = dia[ i - j ] % mod;
				value += col[j] % mod; value %= mod;
				value += ro[i] % mod; value %= mod;
				dia[i - j] += value; dia[i-j] %= mod;
				col[j] += value; col[j] %= mod;
				ro[i] += value; ro[i] %= mod;
				if(i == n - 1 && j == m - 1) ans = value;
			}
		}	
	}

	cout << ans << "\n";
	return 0;
}