#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector <pair <int, int>> A(m);
    for (auto &i: A) cin >> i.first >> i.second;
    int k; cin >> k;
    vector <int> dishes(n+1, 0);
    vector <pair <int, int>> person(k);
    for (int i = 0; i < k; ++i) {
        int a, b; cin >> a >> b;
        person[i] = {a, b};
    }
    int ans = 0;
    function <void(int)> go = [&](int pos) {
        if (pos >= k) {
            int res = 0;
            for (auto i: A) {
                if (dishes[i.first] and dishes[i.second]) res++;
            }
            ans = max(ans, res);
            return;
        }
        dishes[person[pos].first]++;
        go(pos+1);
        dishes[person[pos].first]--;
        dishes[person[pos].second]++;
        go(pos+1);
        dishes[person[pos].second]--;
    };

    go(0);
    cout << ans;
}


/*

*/
#include <bits/stdc++.h>

using namespace std;

struct p{
    long long int w;
    long long int c;
};

p tab[200007];
vector <long long int> edges[200007];

int main()
{
    long long int m, x, y, n, j, i, z=-1000000000000000007, a, b=1, m1=0, m2=0;
    cin >> n >> m;
    for(i=0; i<n; i++){
        cin >> a;
        tab[i].w=a;
        tab[i].c=-1000000000000000007;
    }
    for(i=0; i<m; i++){
        cin >> a >> b;
        edges[a-1].push_back(b-1);
    }
    for(i=0; i<n; i++){
        for(j=0; j<edges[i].size(); j++){
            tab[edges[i][j]].c=max(tab[edges[i][j]].c, max(tab[edges[i][j]].w-tab[i].w+tab[i].c, tab[edges[i][j]].w-tab[i].w));
            z=max(z, tab[edges[i][j]].c);
        }
    }
    cout << z << '\n';
    return 0;
}
