#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int GetDigit(ll num){
    return std::to_string(num).length();
}
bool check(int i){
  int N=i+1;
  if(N==2 || N==4 || N==8 || N==16 || N==32 || N==64 || N==128 || N==256 || N==512 || N==1024 || N==2048 || N==4096 || N==8192 || N==16384 || N==32768 || N==65536) return true;
  else return false;
}
int main(){
  int N;
  cin>>N;
  vector<int> V(100010);
  V[0]=1;
  for(int i=1;i<100010;i++){
    V[i]=V[i-1];
    if(check(i)) V[i]++;
  }

  for(int i=0;i<N;i++) cout<<V[i]<<" ";
return 0;}

/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 998244353;
map<ll, vl>g;
vl a, b;
ll vis[200010], s1[200010], s2[200010];
void dfs(int node, int par)
{
	vis[node] = 1;
	s1[par-1] += a[node-1];
	s2[par-1] += b[node-1];
	FR(i, g[node])
	{
		if(!vis[i])
			dfs(i, par);
	}
}
void solve()
{
	IN(n)IN(m);
	FOR(i, 0, n)
	{
		IN(in);
		a.push_back(in);
	}
	FOR(i, 0, n)
	{
		IN(in);
		b.push_back(in);
	}
	FOR(i, 0, m)
	{
		IN(in1)IN(in2);
		g[in1].pb(in2);
		g[in2].pb(in1);
	}
	FOR(i, 1, n + 1)
	{
		if(!vis[i])
			dfs(i, i);
	}
	FOR(i, 0, n)
		if (s1[i] != s2[i])
		{
			cout << "No";
			return;
		}
	cout << "Yes";
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}