#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);

vector<ll>g[300005];
ll vis[300005]={0};
ll c=0,s1=0,s2=0;
ll a[3000005],b[300005];

void dfs(ll current) {
    vis[current]=1;
    s1 += a[current];
    s2 += b[current];
    for(ll i=0;i<g[current].size();i++) {
        ll child = g[current][i];
        if(vis[child]==0){
            dfs(child);
        }
    }
}

int main(){
    flash;
    ll t=1;
    //cin >> t;
    while(t--) {
        ll n,e;
        cin >> n >> e;
        rep(i,1,n+1) {
            cin >> a[i];
        }
        rep(i,1,n+1) {
            cin >> b[i];
        }
        rep(i,0,e) {
            ll a,b;
            cin >> a >> b;
            g[a].pb(b);
            g[b].pb(a);
        }
        ll f =0;
        ll ans;
        for(ll i=0;i<n;i++){
            s1=0,s2=0;
            if(vis[i]==0){
                dfs(i);
            }
            if(s1 != s2) {
                //cout<<"No\n";
                f=0;
                break;
            }
            else f=1;
        }
        if(f==0) {
            cout<<"No\n";
        }
        else {
            cout<<"Yes\n";
        }
        for(ll i=0;i<=n;i++){
            g[i].clear();
        }
        for(ll i=0;i<=n;i++)vis[i]=0;
        
    }
}


//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}

#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    ll n,x; In(n,x);
    vll a(n); In(a);
    sort(ALL(a)); reverse(ALL(a));
    ll ans = (x-a[a.size()-1]);

    FOR(sz, 2, n+1) {
        vector<vector<vll>> dp(n+1, vector<vll>(sz,vll(sz+1,-1)));
        dp[0][0][0] = 0;
        REP(i,n) {
            REP(j,sz) {
                REP(k,sz+1) {
                    if (k+1 <= sz && dp[i][j][k] != -1) dp[i+1][(j+a[i])%sz][k+1] = max(dp[i+1][(j+a[i])%sz][k+1], dp[i][j][k] + a[i]);
                    if (dp[i][j][k] != -1) dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                }
            }
        }
        if (dp[n][x%sz][sz] != -1) chmin(ans, (x-dp[n][x%sz][sz])/sz);
    }
    Out(ans);
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}

