#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sz(x) (ll)x.size()
#define m1(x) memset(x, 1, sizeof(x))
#define m0(x) memset(x, 0, sizeof(x))
#define inf(x) memset(x, 0x3f, sizeof(x))
#define flout cout << fixed << setprecision(12)
#define MOD 1000000007
int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for (int i = 0; i < m; i ++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int k;
    cin >> k;
    int c[k], d[k];
    for (int i = 0; i < k; i ++) {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }
    bool cur[n];
    int ans = 0;
    for (int i = 0; i < (1 << k); i ++) {
        m0(cur);
        for (int j = 0; j < k; j ++) {
            if ((1 << j) & i) {
                cur[d[j]] = true;
            }
            else {
                cur[c[j]] = true;
            }
        }
        int counter = 0;
        for (int i = 0; i < m; i ++) {
            if (cur[a[i]] && cur[b[i]]) {
                counter ++;
            }
        }
        ans = max(ans, counter);
    }
    cout << ans << endl;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
#define int long long
signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    vector<int>c(n+1);
    c[0] = k;
    rep(i,n){
        if(c[a[i]]>0){
            c[a[i]]--;
            c[a[i]+1]++;
        }
    }
    ll sm = 0;
    rep(i,n+1){
        sm += c[i]*(ll)i;
    }
    cout << sm << endl;
    return 0;
}