#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;


// ----------------  modint ---------------------//

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const { //値をt乗する
    if (!t) return 1; // t == 0
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this; //*thisは元の値(t乗する対象)
    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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[2050][2050];
mint X[2050][2050];
mint Y[2050][2050];
mint Z[2050][2050];

int main(){
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        int h,w; cin >> h >> w;
        char s[h][w];
        rep(i,h){
                rep(j,w){
                        cin >> s[i][j];
                }
        }

        if(s[0][0] == '#' || s[h-1][w-1] == '#'){ cout << "0" << endl; return 0;}

        rep(i,2050)rep(j,2050){
                dp[i][j] = mint(0);
                X[i][j] = mint(0);
                Y[i][j] = mint(0);
                Z[i][j] = mint(0);
        }
        dp[0][0] = mint(1);

        rep(i,h)rep(j,w){
                if(i == 0 && j == 0) continue;
                if(s[i][j] == '#') continue;
                if(j>0) X[i][j] = X[i][j-1] + dp[i][j-1];
                if(i>0) Y[i][j] = Y[i-1][j] + dp[i-1][j];
                if(j>0 && i>0) Z[i][j] = Z[i-1][j-1] + dp[i-1][j-1];
                dp[i][j] = mint(X[i][j] + Y[i][j] + Z[i][j]);
        }

        cout << dp[h-1][w-1] << endl;

        return 0;
}
//a.9
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define endll endl
#define endl '\n'
#define INF 1e18
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n'
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n'
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n'
#define output(container) for(auto x:container)cout<<x<<" ";cout<<'\n';
#define popcnt __builtin_popcountll
#define precise(x) fixed << setprecision(x)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
const ll mod=1000000007;
const ll maxN=50005;

ll ceill(ll a,ll b){return a/b+bool(a%b);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
void bin(unsigned n,string &str){str="";if(n>1)bin(n>>1,str);str+=to_string(n&1);}
bool isPrime(ll n)
{
    if(n<=1)return false;else if(n<=3)return true;else if(n%2==0 || n%3==0)return false;
    for(ll i=5;i*i<=n;i=i+6){if(n%i==0 || n%(i+2)==0)return false;}return true;
}

vector<ll>primes;
void SieveOfEratosthenes()
{
    bool prime[maxN];primes.clear();
    memset(prime, true, sizeof(prime));
    for(ll i=2;i*i<maxN;i++)if(prime[i]==true)for(ll j=i*i;j<maxN;j+=i)prime[j]=false;
    for(ll i=2;i<maxN;i++)if(prime[i])primes.push_back(i);
}
//vector<ll>fact(maxN);
//void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i)%mod;}
//ll mul(ll a,ll b){return (a*1LL*b)%mod;}
//ll nCr(ll n,ll k){if(k>n)return 0;return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));}

/*ll spf[maxN];
void sieve()
{
    spf[1]=1;for(ll i=2;i<maxN;i++)spf[i]=i;for(ll i=4;i<maxN;i+=2)spf[i]=2;
    for(ll i=3;i*i<maxN;i++){if(spf[i]==i)for(ll j=i*i;j<maxN;j+=i)if(spf[j]==j)spf[j]=i;}
}
vector<ll>getfacts(ll x){vector<ll>vec;while(x!=1)vec.push_back(spf[x]),x=x/spf[x];return vec;}*/

/*ll fen[maxN];
void update(ll i,ll val,ll n){i++;for(;i<=n;i+=i&-i)fen[i]+=val;}
ll get(ll i){i++;ll res=0;for(;i>0;i-=i&-i)res+=fen[i];return res;}*/

/*ll phi[maxN];
void Eul_Toi_phi_precompute()
{
    for(ll i=0;i<maxN;i++)phi[i]=i;
    for(ll i=2;i<maxN;i++)if(phi[i]==i){phi[i]=i-1;for(ll j=i+i;j<maxN;j+=i)phi[j]-=phi[j]/i;}
}*/
vector<vector<ll>>graph;
bool vis[2005];
ll subsz[2005];
void dfs(ll node)
{
    vis[node]=1;
    subsz[node]=1;
    for(ll child:graph[node])
    {
        if(vis[child]==0)dfs(child),subsz[node]+=subsz[child];
    }
}
void solve()
{
    ll n,m;cin>>n>>m;graph.clear();graph.resize(n+1);
    vector<ll>a(m);
    for(ll i=0;i<m;i++){ll b;cin>>a[i]>>b;graph[a[i]].push_back(b);}
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        memset(subsz,0,sizeof subsz);
        dfs(i);
        ll t=subsz[i];
        //deb2(i,subsz[i]);
        cnt+=t;
    }
    cout<<cnt<<endl;
}
signed main()
{
    ios;
    ll tc=1; //cin>>tc;
    for(ll t=1;t<=tc;t++)
    {
        //CASE(t);
        solve();
    }
    //cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
}
