//code bcuz love,code 4 hate
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register int
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 51
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
ll n,ans=5e18;
ll a[N],p[N],tot,b[N][N];
inline void Solve(ll x,ll v)
{
	ll tmp=v;
	for(re i=2;i*i<=v;i++)
	{
		if(tmp%i==0){b[x][i]=1;while(tmp%i==0)tmp/=i;}
	}
	if(tmp>1){b[x][tmp]=1;}
}
inline ll check(ll x){for(re i=2;i<x;i++)if(x%i==0)return 0;return 1;}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();FOR(i,1,n)a[i]=read(),Solve(i,a[i]);
	FOR(i,2,50)if(check(i))p[++tot]=i;
	FOR(S,0,(1<<tot)-1)
	{
		ll v=1;
		FOR(i,0,tot-1)if((S>>i)&1)v*=p[i+1];
		ll fl=1;
		FOR(i,1,n)
		{
			ll flag=0;
			FOR(j,0,tot-1)if((S>>j)&1)if(b[i][p[j+1]]){flag=1;}
			if(!flag){fl=0;break;}
		}
		if(fl)ans=min(ans,v);
	}
	cout<<ans<<'\n';
	return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
//#include<atcoder/all>
//using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
//typedef __int128_t llint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;

int main(void){
    int N,M;
    cin >> N >> M;
    int A[M],B[M];
    rep(i,M) cin >> A[i] >> B[i],A[i]--,B[i]--;
    int K;
    cin >> K;
    int C[K],D[K];
    rep(i,K) cin >> C[i] >> D[i],C[i]--,D[i]--;
    int ans=0;
    rep(i,(1<<K)){
        int sara[N]={};
        rep(j,K){
            if(i&(1<<j)) sara[C[j]]++;
            else sara[D[j]]++;
        }
        int res=0;
        rep(j,M) if(sara[A[j]] && sara[B[j]]) res++;
        ans=max(ans,res);
    }
    cout << ans << endl;
}