#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node {
	int to,next;
} a[400005];
int aa[200005],b[200005],suma,sumb;
int h[200005],cnt,use[200005],st[200005],top;
void add(int x,int y) {
	cnt++;
	a[cnt].to=y;
	a[cnt].next=h[x];
	h[x]=cnt;
}
void dfs(int v) {
	st[++top]=v;
	use[v]=1;
	for(int i=h[v]; i; i=a[i].next) {
		if(!use[a[i].to]) {
			dfs(a[i].to);
		}
	}
	return ;
}
signed main() {
	int n,m,f=1;
	scanf("%lld%lld",&n,&m);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&aa[i]);
		suma+=aa[i];
	}
	for(int i=1; i<=n; i++) {
		scanf("%lld",&b[i]);
		sumb+=b[i];
	}
	for(int i=1; i<=m; i++) {
		int x,y;
		scanf("%lld%lld",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(int i=1; i<=n; i++) {
		if(aa[i]!=b[i]) {
			f=0;
		}
	}
	if(f==1) {
		printf("Yes");
		return 0;
	}
	if(suma!=sumb) {
		printf("No");
		return 0;
	}
	for(int i=1; i<=n; i++) {
		if(!use[i]) {
			top=0;
			dfs(i);
			int sa=0,sb=0;
			for(int j=1; j<=top; j++) {
				sa+=aa[st[j]];
				sb+=b[st[j]];
			}
			if(sa!=sb) {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template <class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 210, size = 1 << 20, mod = 998244353, inf = 2e9;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o> void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
template <class o> void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar('\n');
}

int n, a[N], b[N], p[N];
bool vis[N], f[N];

void ex() {
    puts("No");
    exit(0);
}

void add(int x, int y) {
    if (~x) {
        if (vis[x])
            ex();
        vis[x] = 1;
        p[x] = y;
    }
}

bool pd(int l, int r) {
    int len = (r - l + 1) / 2, mid = l + len;
    for (int i = l; i < mid; i++) {
        if (vis[i]) {
            if (~p[i]) {
                if (p[i] != i + len)
                    return 0;
            } else if (vis[i + len])
                return 0;
        } else {
            if (~p[i + len])
                return 0;
        }
    }
    return 1;
}

int main() {
    qr(n);
    memset(p, -1, sizeof p);
    for (int i = 1; i <= n; i++) {
        qr(a[i]);
        qr(b[i]);
        add(a[i], b[i]);
        add(b[i], a[i]);
        if (~a[i] && ~b[i] && a[i] >= b[i])
            ex();
    }
    n *= 2;
    f[0] = 1;
    for (int i = 2; i <= n; i += 2)
        for (int j = 0; j < i; j += 2)
            f[i] |= f[j] && pd(j + 1, i);
    puts(f[n] ? "Yes" : "No");
    return 0;
}
