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

const int MAX_N = 200000;

int n, m;
vector<int> adj[MAX_N];
long long int a[MAX_N], b[MAX_N];

bool vis[MAX_N];

long long dfs(int u) {
    long long ans = a[u] - b[u];
    vis[u] = true;

    for (int v : adj[u]) {
        if (vis[v])
            continue;
        ans += dfs(v);
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        vis[i] = false;
    }

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[--u].push_back(--v);
        adj[v].push_back(u);
    }

    for (int i = 0; i < n; i++) {
        if (vis[i])
            continue;
        if (dfs(i) != 0) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int N, M, A[500], B[500];
vector<int> Adj[25];

int used[25];

int loop;
int cnt;
long long int num;
int color[25];
vector<int> child[25];

vector<int> V;

void visit(int k) {

	used[k] = 1; V.push_back(k);

	cnt++;
	for (auto y : Adj[k]) {
		if (used[y] == 0) { child[k].push_back(y);  visit(y); }
	}
}

int po;


void dfs(int k) {


		for (int j = 0; j <= 2; j++) {
			int possible = 1;
			for (auto y : Adj[k]) {
				if (color[y] == j) { possible = -1; break; }
			}
			if (possible==1) {
				color[k] = j;  po++; if (po == cnt) {
					//for (int i = 1; i <= N; i++) { cout << "color[" << i << "]= " << color[i] << endl; }
					num++;
				}
				else {
					for (auto z : child[k]) {
						 dfs(z); 
					}
				}
				color[k] = -1;  po--;
			}
		}


}

void CALC(int k) {

	int M = V.size();
	if (k == M) { num++; return; }

	for (int j = 0; j <= 2; j++) {

		int possible = 1;
		for (auto y : Adj[V[k]]) {
			if (color[y] == j) { possible = -1; break; }
		}
		if (possible == 1) {
			color[V[k]] = j; 
			CALC(k + 1);
			color[V[k]] = -1; 
		}

	}
	


}

int main(void) {

	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		 Adj[A[i]].push_back(B[i]);
		 Adj[B[i]].push_back(A[i]);
	}

	

	long long int ans = 1;

	for (int i = 1; i <= N; i++) {
		if (used[i] == 0) {
			V.clear();
			cnt = 0;
			visit(i);
			//cout << "cnt= " << cnt << endl;
			for (int i = 1; i <= N; i++) { color[i] = -1; }
			num = 0; po = 0;
			CALC(0);
			ans *= num;
		}
	}

	cout << ans << endl;

	return 0;
}
