#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<vector<int>> g;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int ma = 1000000001, MA = -1;
  rep(i, n) {
    cin >> a[i];
    if (ma > a[i]) ma = a[i];
    if (MA < a[i]) MA = a[i];
  }

  g.resize(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x;--y;
    g[y].push_back(x);
  }
  vector<int> dp(n, -1);

  rep(i, n) {
    if (dp[i] >= 0) continue;
    int res = 1e9+1;
    for (auto x : g[i]) {
      if (dp[x] == -1) res = min(res, a[x]);
      else res = min({res, dp[x], a[x]});
    }
    dp[i] = res;
  }

  int ans = -1e9;
  for (int i = 0; i < n; i++) {
    if (dp[i] == 1e9+1) continue;
    ans = max(ans, a[i] - dp[i]);
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
/* #include <atcoder/all> */

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

using ll = long long;
using P = pair<int, int>;

const int MOD = 1'000'000'007;

template<class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }
  vector<vector<ll>> r(h, vector<ll>(w));
  vector<vector<ll>> d(h, vector<ll>(w));
  vector<vector<ll>> rd(h, vector<ll>(w));
  vector<vector<ll>> dp(h, vector<ll>(w, 0));
  dp.at(0).at(0) = 1;
  rep(i, h) {
    rep(j, w) {
      if (s.at(i).at(j) == '#') {
        r.at(i).at(j) = 0;
        d.at(i).at(j) = 0;
        rd.at(i).at(j) = 0;
        continue;
      }
      // r
      int oi = i - 1;
      int oj = j;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        r.at(i).at(j) += dp.at(oi).at(oj);
        r.at(i).at(j) += r.at(oi).at(oj);
      }
      // d
      oi = i;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        d.at(i).at(j) += dp.at(oi).at(oj);
        d.at(i).at(j) += d.at(oi).at(oj);
      }
      // rd
      oi = i - 1;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        rd.at(i).at(j) += dp.at(oi).at(oj);
        rd.at(i).at(j) += rd.at(oi).at(oj);
      }
      dp.at(i).at(j) += r.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += d.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += rd.at(i).at(j);
      dp.at(i).at(j) %= MOD;
    }
  }
  cout << dp.at(h - 1).at(w - 1) << endl;
  return 0;
}

