		#include<bits/stdc++.h>
            #define cs const 
            #define fr first 
            #define se second
           #define ls (now<<1)
           #define mp make_pair
           #define pb push_back
           #define ll long long
           #define ppb pop_back
           #define rs (now<<1|1)
           #define int long long
           #define mid ((l+r)>>1)
          #define low(i) (i&(-i))
         #define par pair<int,int>
   #define cn(x) memset(x, 0, sizeof(x))
 #define rep(i, x, y) for(int i=x; i<=y; ++i)
 #define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

using namespace std;

cs int G = 3;
cs int ff = 3e6 + 15;
cs int inf = 1e18 + 1;
cs int base = 4;
cs int M = 998244353;

int n, m, a[ff], b[ff], fa[ff];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void init()
{
	cin >> n >> m;
	rep(i, 1, n) fa[i] = i;
	rep(i, 1, n) scanf("%lld", &a[i]);
	rep(i, 1, n) scanf("%lld", &b[i]);
	rep(i, 1, m)
	{
		int u, v; scanf("%lld %lld", &u, &v);
		int fau = find(u), fav = find(v);
		if(fau != fav)
			fa[fau] = fav, a[fav] += a[fau], b[fav] += b[fau];
	}
	rep(i, 1, n)
		if(a[find(i)] != b[find(i)])
		{
			puts("No"); return;
		}
	puts("Yes");
}
signed main()
{
//	freopen("1.in", "r", stdin);
//	freopen("number.out", "w", stdout);
	int Ts = 1;
	while(Ts--)
		init();
}
/*
2 8
push 1 1 1
push 1 2 1
push 2 3 2
put 1 2
put 2 1
put 1 2
put 2 1
pop 1 1
*/
#include <bits/stdc++.h>

using namespace std;

#define ffor(i,o,f)		   for(int i = o; i < f; i++)
#define pb 				   push_back
#define mp                 make_pair
#define all(a)             (a).begin(), (a).end()
#define F                  first
#define S                  second
#define PI 				   3.14159265358979323846264338327950
#define endl 			   '\n'
#define lcm(a,b)           (a*b)/__gcd(a,b)
typedef long long          ll;
typedef pair < int, int >  pii;
typedef vector < int >     vi;
typedef vector < pii >     vii;
typedef vector < vi > 	   gi;
typedef vector < ll >      vll;
typedef map < int, int >   mii;
const int INF = int(1e9 + 7);

int main() //IBMG
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    string s;
    int aux;
    bool ok;
    mii m;
    mii mm;
    cin >> s;
    ffor(i, 0, s.size()) m[s[i]-48] ++;
    mm = m;
    if (s.size() == 1)
    {
    	if (s[0] == '8') cout << "Yes" << endl;
    	else cout << "No" << endl;
    	return 0;
    }
    if (s.size() == 2)
    {
    	for (int i = 16; i <= 96; i += 8)
        {
    	    aux = i;
    	    ok = true;
    	    while (aux >= 1)
    	    {
    	    	if (m[aux%10] > 0) m[aux%10] --;
    	    	else ok = false;
    	    	aux /= 10;
    	    }
    	    m = mm;
    	    if (ok)
    	    {
    	    	cout << "Yes" << endl;
    	    	break;
    	    }
    	    else if (i == 96) cout << "No" << endl;
        }
        return 0;
    }
    for (int i = 104; i <= 992; i += 8)
    {
    	aux = i;
    	ok = true;
    	while (aux >= 1)
	    {
	    	if (m[aux%10] > 0) m[aux%10] --;
	    	else ok = false;
	    	aux /= 10;
	    }
	    m = mm;
	    if (ok)
	    {
	    	cout << "Yes" << endl;
	    	break;
	    }
	    else if (i == 992) cout << "No" << endl;
    }
    return 0; 
}