#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, X;
	cin >> N >> X;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];
	// dp[i][j] := i個使っていて、Xとの差をiで割ったあまりがjのものの中で最大
  int64 res = 2*INF_LL;
	FOR(k, 1, N+1) {
	  auto dp = make_v<int64>(k + 1, k + 1);
	  fill_v<int64>(dp, -INF_LL);
	  dp[0][0] = 0;

	  REP(s, N) {
      for (int64 i = k-1; i >= 0; i--) {
        REP(j, k) {
            assert(i < dp.size() && j < dp[0].size());
	        if (dp[i][j] != -INF_LL)
  	        chmax(dp[i + 1][(j + A[s]) % k], dp[i][j] + A[s]);
	      }
	    }
	  }
//	  cout << k << " " << dp[k][X%k] << " " << (X - dp[k][X%k]) % k << endl;
	  if(dp[k][X%k]!=-INF_LL)chmin(res, (X - dp[k][X % k]) / k);
  }
	cout << res << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = std::pair<ll, ll>;
template <class T> using vec = std::vector<T>;
template <class T> using vec2 = std::vector<vec<T>>;
template <class T> using vec3 = std::vector<vec2<T>>;
#define debug(var) std::cerr << #var << " : " << var << std::endl;
#define rep(i, N) for (ll i = 0, i##_len=(N); i < i##_len; i++)
#define rrep(i, N) for (ll i = (N) - 1; i >= 0; i--)
#define range(i, A, B) for (ll i = (A), i##_len = (B); i < i##_len; i++)
constexpr int MOD = 1000000007;
constexpr ll INFL = std::numeric_limits<ll>::max();
template <class T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }

void solve()
{
    ll N, M;
    cin >> N >> M;
    vec2<ll> A(M, vec<ll>(2));
    rep(i, M) {
        cin >> A[i][0] >> A[i][1];
    }
    ll K;
    cin >> K;
    vec2<ll> C(K, vec<ll>(2));
    rep(i, K) {
        cin >> C[i][0] >> C[i][1];
    }

    ll ret = 0;
    rep(i, 1 << K) {
        // debug(i);
        vec<bool> P(N + 10);
        rep(j, K) {
            if ((i & (1 << j)) == 0)
                P[C[j][0]] = true;
            else
                P[C[j][1]] = true;
        }

        // rep(i, N + 1) {
        //     cerr << (ll)P[i] << " ";
        // }
        // cerr << endl;

        ll max = 0;
        rep(j, M) {
            if (P[A[j][0]] && P[A[j][1]]) {
                max++;
            }
        }
        chmax(ret, max);
    }
    cout << ret << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(10);
    solve();
    std::cout << std::flush;
    return 0;
}