#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main(){
    ll h,w,m; cin >> h >> w >> m;
    vector<P> o(m);
    rep(i,m){
        cin >> o[i].first >> o[i].second;
        o[i].first--; o[i].second--;
    }

    vector<int> index[h+1];
    rep(i,m) index[o[i].first].pb(o[i].second);
    rep(i,h) sort(ALL(index[i]));

    if(index[0].size() > 0){
        int t = index[0][0];
        index[0] = {};
        FOR(i,t,w) index[0].pb(i);
    }

    vector<int> tmp;
    rep(i,m){
        if(o[i].second == 0) tmp.pb(o[i].first);
    }
    if(tmp.size() > 0){
        sort(ALL(tmp));
        int u = tmp[0];
        FOR(i,u,h){
            if(index[i].size() > 0 && index[i][0] == 0) continue;
            index[i].pb(0);
        }
    }

    rep(i,h) index[i].pb(w);
    rep(i,w+1) index[h].pb(i);
    rep(i,h+1) sort(ALL(index[i]));

    /*rep(i,h+1){
        rep(j,(int)index[i].size()){
            cout << index[i][j] << " ";
        }
        cout << endl;
    }*/

    vector<int> index2[w+1];
    rep(i,h+1){
        rep(j,(int)index[i].size()){
            index2[index[i][j]].pb(i);
        }
    }
    rep(i,w+1) sort(ALL(index2[i]));

    BIT<ll> cnt(h+5);
    ll ans = 0;
    rep(i,h) ans += (ll)index[i][0];

    rep(i,index[0][0]){
        ans += cnt.sum(1,(ll)index2[i][0]+1LL);
        for(int j : index2[i]){
            if(cnt.sum(j+1, j+2) == 0) cnt.add(j+1,j+2,1LL);
        }
    }
    cout << ans << endl;
}

//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<ctime>
//#include<algorithm>//next_permutation
#define rep(i,n) for (ll i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;

const ll MOD = 1000000007;
const ll MAX = 2000001;

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);
}



int main(){
  ll n,m; cin >> n >> m;

  vl gold(n);
  rep(i,n) cin >> gold[i];
  
  vector<set<ll>> e(n);

  rep(i,m){
    ll a,b; cin >> a >> b; --a; --b;
    e[a].insert(b);
  }

  vl dp(n,1e18); //その街に持ってこられる最安の金の価格

  rep(i,n){
    for(auto a : e[i]){

      //cout << i << a << endl;
      dp[a] = min({dp[i],dp[a],gold[i]});
    }
  }

  //cout << "aaaaa" << endl;

  ll ans = -1e18;

  rep(i,n){
    ans = max(ans,gold[i] - dp[i]);
  }

  cout << ans << endl;

}