#include <iostream>
#include <algorithm>
#include <cstring>
#define NMAX 101

using namespace std;

int frecv[NMAX], n, m, k, ans;
pair<int, int> ab[NMAX], cd[NMAX];

int res(int start) {
    memset(frecv, 0, sizeof(frecv));
    for (int i = 0; i < k; ++i)
        if (start & (1 << i))
            ++frecv[cd[i].first];
        else
            ++frecv[cd[i].second];

    int rez = 0;
    for (int i = 1; i <= m; ++i)
        if (frecv[ab[i].first] && frecv[ab[i].second])
            ++rez;
    return rez;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
        cin >> ab[i].first >> ab[i].second;
    cin >> k;
    for (int i = 0; i < k; ++i)
        cin >> cd[i].first >> cd[i].second;

    for (int i = 0; i < 1<<k; ++i)
        ans = max(ans, res(i));
    cout << ans;
    return 0;
}

#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<ll, ll>;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
    vector<pair<ll, int>> factor(ll x) {
        vector<pair<ll, int>> res;
        for (int p : primes) {
            int y = 0;
            while (x % p == 0) x /= p, ++y;
            if (y != 0) res.emplace_back(p, y);
        }
        if (x != 1) res.emplace_back(x, 1);
        return res;
    }
};

ll A, B;
unordered_map<ll, int> mp;
ll dp[1 << 20][74];

ll dfs(ll t, int mask) {
    if (dp[mask][t - A] != 0) {
        return dp[mask][t - A];
    }
    if (t > B) {
        return dp[mask][t - A] = 1;
    }

    int tmask = mp[t];
    ll retVal = 0;
    // cerr << "tmask =" << tmask << "bit wise=" << bitset<20>(mask & tmask) << endl;
    if ((mask & tmask) == 0) {
        retVal += dfs(t + 1, mask | tmask);
    }
    retVal += dfs(t + 1, mask);
    return dp[mask][t - A] = retVal;
}

void solve() {
    Sieve sieve(72);
    for (ll i = A; i <= B; i++) {
        int mask = 0;
        rep(j, sieve.primes.size()) {
            if (i % sieve.primes[j] == 0) {
                mask |= (1 << j);
            }
        }
        // cerr << "i=" << i << " mask=" << mask << endl;
        mp[i] = mask;
    }
    dfs(A, 0);
    cout << dp[0][0] << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    scanf("%lld", &A);

    scanf("%lld", &B);
    solve();
    return 0;
}
