#include <bits/stdc++.h>
#define forr(i, l, r) for (int i=l;i<=r;i++)
#define ll long long
#define pii pair <long long, int>
#define f first
#define s second
#define ii long long
#define iii pair <pii, int>
#define endl '\n'
using namespace std;
int const N=5e4 + 1;
vector <pii> adj[N];
int n, m, k;
ll d[N];
ll cnt[N], a[N], b[N];
ll run[N];
void inp()
{
cin >> n >> m;
forr(i, 1, m)
{
ll u, v, w;
cin >> u >> v;
u++, v++;
adj[u].push_back({v, 1});
adj[v].push_back({u, 1});
}
cin >> k;
forr(i, 1, k) {
cin >> a[i] >> b[i];
a[i]++, b[i]++;
// cout << a[i] << " " << b[i] << endl;
}
}
void bfs1(int u1)
{
queue <int> q;
forr(i, 1, n)
d[i] = -1;
q.push(u1);
d[u1] = 1;
cnt[u1] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto[v, w] : adj[u])
if (d[v] == -1)
{
d[v] = d[u] + 1;
cnt[v] = cnt[u];
q.push(v);
}
else if (d[v] == d[u] + 1)
{
cnt[v] += cnt[u];
}
}
}
ll e[2002][5002];
pii ps(ll x, ll y)
{
return {x/__gcd(x, y), y/__gcd(x, y)};
}
bool cmp(iii a, iii b)
{
if (a.f.f * b.f.s == a.f.s * b.f.f)
return a.s < b.s;
return a.f.f * b.f.s < a.f.s * b.f.f;
}
pii cong(pii a, pii b)
{
ll o = a.f * b.s;
ll o2 = b.f * a.s;
return ps(o + o2, a.s * b.s);
}
void bfs(ll u1, int i)
{
queue <int> q;
q.push(u1);
e[i][u1] = cnt[u1];
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto[v, w] : adj[u])
if (d[v] + w == d[u])
{
// cout << i << " " << u << " " << v << endl;
e[i][v] = cnt[v];
q.push(v);
}
}
}
iii ans[N];
int main()
{
freopen("traincentre.inp", "r", stdin);
freopen("traincentre.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
forr(i, 1, k)
{
bfs1(a[i]);
run[i] = cnt[b[i]];
// forr(j, 1, n)
// cout << i <<" " << j << " " << cnt[j] << endl;
// cout << run[i] << " " << i << endl;
bfs(b[i], i);
forr(z, 1, n) cnt[z] = 0, d[z] = 0;
}
forr(j, 1, n) {
pii x = {0, 1};
forr(i, 1, k) {
x = cong(x, ps(e[i][j], run[i]));
// cout << e[i][j] << " " << i << ' ' << j - 1 << endl;
}
//cout << x.f << " " << x.s << " " << j << endl;
//cout << x.f << " " << x.s << " " << j << endl;
ans[j] = {x, j};
}
sort(ans + 1, ans + 1 + n, cmp);
cout << ans[n].s - 1;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZm9ycihpLCBsLCByKSBmb3IgKGludCBpPWw7aTw9cjtpKyspCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGlpIHBhaXIgPGxvbmcgbG9uZywgaW50PgojZGVmaW5lIGYgZmlyc3QKI2RlZmluZSBzIHNlY29uZAojZGVmaW5lIGlpIGxvbmcgbG9uZwojZGVmaW5lIGlpaSBwYWlyIDxwaWksIGludD4KI2RlZmluZSBlbmRsICdcbicKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBjb25zdCBOPTVlNCArIDE7CnZlY3RvciA8cGlpPiBhZGpbTl07CmludCBuLCBtLCBrOwpsbCBkW05dOwpsbCBjbnRbTl0sIGFbTl0sIGJbTl07CmxsIHJ1bltOXTsKdm9pZCBpbnAoKQp7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9ycihpLCAxLCBtKQogICAgewogICAgICAgIGxsIHUsIHYsIHc7CiAgICAgICBjaW4gPj4gdSA+PiB2OwogICAgICAgdSsrLCB2Kys7CiAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh7diwgMX0pOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2soe3UsIDF9KTsKICAgIH0KICAgIGNpbiA+PiBrOwoKICAgIGZvcnIoaSwgMSwgaykgewogICAgY2luID4+IGFbaV0gPj4gYltpXTsKICAgIGFbaV0rKywgYltpXSsrOwovLyAgICBjb3V0IDw8IGFbaV0gPDwgIiAiIDw8IGJbaV0gPDwgZW5kbDsKICAgIH0KfQp2b2lkIGJmczEoaW50IHUxKQp7CiAgICBxdWV1ZSA8aW50PiBxOwogICAgZm9ycihpLCAxLCBuKQogICAgZFtpXSA9IC0xOwogICAgcS5wdXNoKHUxKTsKICAgIGRbdTFdID0gMTsKICAgIGNudFt1MV0gPSAxOwogICAgd2hpbGUgKCFxLmVtcHR5KCkpIHsKICAgICAgICAgICAgaW50IHUgPSBxLmZyb250KCk7CiAgICBxLnBvcCgpOwogICAgZm9yIChhdXRvW3YsIHddIDogYWRqW3VdKQogICAgICAgIGlmIChkW3ZdID09IC0xKQogICAgICAgIHsKICAgICAgICAgICAgIGRbdl0gPSBkW3VdICsgMTsKICAgICAgICAgICAgIGNudFt2XSA9IGNudFt1XTsKICAgICAgICAgICAgcS5wdXNoKHYpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChkW3ZdID09IGRbdV0gKyAxKQogICAgICAgIHsKICAgICAgICAgICAgY250W3ZdICs9IGNudFt1XTsKICAgICAgICB9Cn0KfQpsbCBlWzIwMDJdWzUwMDJdOwpwaWkgcHMobGwgeCwgbGwgeSkKewogICAgcmV0dXJuIHt4L19fZ2NkKHgsIHkpLCB5L19fZ2NkKHgsIHkpfTsKfQpib29sIGNtcChpaWkgYSwgaWlpIGIpCnsKCiAgICAgICAgaWYgIChhLmYuZiAqIGIuZi5zID09IGEuZi5zICogYi5mLmYpCiAgICAgICAgICAgIHJldHVybiBhLnMgPCBiLnM7CiAgICAgICAgICAgIHJldHVybiBhLmYuZiAqIGIuZi5zIDwgYS5mLnMgKiBiLmYuZjsKfQpwaWkgY29uZyhwaWkgYSwgcGlpIGIpCnsKICAgIGxsIG8gPSBhLmYgKiBiLnM7CiAgICBsbCBvMiA9IGIuZiAqIGEuczsKICAgIHJldHVybiBwcyhvICsgbzIsIGEucyAqIGIucyk7Cn0Kdm9pZCBiZnMobGwgdTEsIGludC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