#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const i64 INF = (i64) 1e18 + 42;
const int MOD = (int) 1e9 + 7;

inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int mpow(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return mpow(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, mpow(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}

char a[2010][2010];
int dp[4][2010][2010];

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int k = 0;
  int n, m; cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        dp[0][i][j] = 1 + dp[0][i - 1][j];
        dp[1][i][j] = 1 + dp[1][i][j - 1];
        ++k;
      }
    }
  }
  int ans = 0;
  for (int i = n; i > 0; --i) {
    for (int j = m; j > 0; --j) {
      if (a[i][j] == '.') {
        dp[2][i][j] = 1 + dp[2][i + 1][j];
        dp[3][i][j] = 1 + dp[3][i][j + 1];
        int tot = k - (dp[0][i][j] + dp[1][i][j] + dp[2][i][j] + dp[3][i][j] - 3);
        adds(ans, mpow(2, tot));
      }
    }
  }
  ans = sub(mul(k, mpow(2, k)), ans);
  kek(ans);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dd;
#define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++)
#define nl cout<<"\n";
#define forn(a,b) for (int ii=a;ii<b;ii++)
const ll MOD1=1e9+7;
const ll MOD2=998244353;
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define hhh cout<<"here"<<endl;

ll mod=MOD1;
ll po(ll x,ll y) {if(y<0)return 0;y%=mod;ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
ll gcd(ll a, ll b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);}

void dfs(int u,vi&a,vector<vi>&adj,vi&vis,vi&dp){
	vis[u]=1;
	if(adj[u].size()==0){
		dp[u]=-1e9;return;
	}
	for(auto v:adj[u]){
		if(!vis[v])dfs(v,a,adj,vis,dp);
		dp[u]=max(dp[u],max(a[v],dp[v]));
	}
}
void solve(){
	int n,m;cin>>n>>m;
	vi a(n+1);forn(0,n)cin>>a[ii+1];
	vector<vi>adj(n+1);
	forn(0,m){
		int u,v;cin>>u>>v;
		adj[u].pb(v);
	}vi dp(n+1);
	vi vis(n+1);
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i,a,adj,vis,dp);
			vis[i]=1;
		}
	}int mx=-1e9;
	forn(1,n+1){
		mx=max(mx,dp[ii]-a[ii]);
	}cout<<mx;
}
int main(){
    // fastio
    // ++*(int*)0;// crash
    // freopen("in.txt","r",stdin);freopen("outt.txt","w",stdout);
    // tst
    {
        solve();nl;
    }
}
/*

4
 13 12   7  11 16   15 2  14



*/
