#include<bits/stdc++.h>
using namespace std;
const int p = 31;
const int m = 998244353;
typedef long long ll;
typedef long double d;
typedef unsigned long long ull;
typedef int in;
#define ar array
#define ff first
#define ss second
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

bitset<200005>isp;
vector<int>prm;
ll dp[200005];
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    dp[1] = 1;
    for (int i = 2; i <= n; ++i) {
        dp[i]+=dp[i-1];
        ll tmp = i;
        ll ans = 1ll;
        for (int x=2;x*x<=tmp;++x) {
            if (tmp <= 1)break;
            int ctr = 0;
            while (tmp % x == 0) {
                tmp /= x;
                ctr++;
            }
            if (ctr) {
                ans *= (((ctr + 2) * (ctr + 1) / 2));
            }
        }
        if(tmp!=1){
            ans*=(3);
        }
        dp[i]+=ans;
    }
    cout<<dp[n];
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time

    return 0;
}

#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
//#define NDEBUG
#endif
#include<bits/stdc++.h>
#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
const int N=200005;
int n,m,fa[N],a[N],b[N],sa[N],sb[N];
int fd(int k1){return fa[k1]==k1?k1:fa[k1]=fd(fa[k1]);}
signed main(){
	rd(n),rd(m);
	rep(i,1,n)rd(a[i]);
	rep(i,1,n)rd(b[i]),fa[i]=i;
	rep(i,1,n)fa[i]=i;
	rep(i,1,m){
		int k1,k2;
		rd(k1),rd(k2);
		fa[fd(k1)]=fd(k2);
	}
	rep(i,1,n){
		sa[fd(i)]+=a[i];
		sb[fd(i)]+=b[i];
	}
	rep(i,1,n)if(sa[i]!=sb[i]){
		puts("No");
		exit(0);
	}
	puts("Yes");
	return 0;
}
