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

typedef long long ll;

const int N=2e5+5;

vector<int> adj[N];
int vis[N];

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n, m; cin >> n >> m;
  ll a[n];
  for (int i = 0; i < n; ++i){
    cin >> a[i];
  }
  ll b[n];
  for (int i = 0; i < n; ++i){
    cin >> b[i];
  }
  for (int i = 0; i < m; ++i){
    int c, d; cin >> c >> d;  c--, d--;
    adj[c].push_back(d);
    adj[d].push_back(c);
  }
  string ans = "Yes";
  for (int i = 0; i < n; ++i){
    if(!vis[i]){
      ll sum = 0;
      queue<int> q; q.push(i);
      vis[i]=1;
      while (!q.empty()){
        int u = q.front();  q.pop();
        sum += a[u]-b[u];
        for(int v: adj[u]){
          if(!vis[v]) q.push(v), vis[v]=1;
        }
      }
      if(sum!=0)  ans = "No";
    }
  }
  cout << ans << "\n";
  
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 1e-8
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int N = 3e5 + 5;
const int M = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const ll LL_MAX = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
#define mid (l + r >> 1)
#define ls (o << 1)
#define rs (o << 1 | 1)
#define lson ls, l, mid
#define rson rs, mid + 1, r
inline ll read(){
    ll ans = 0; int f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') {ans = ans * 10 + c - '0'; c = getchar();}
    return ans * f;
}
int a[N];
map<int, int>ma;
vector<int>ve;
int main(){
    int n = read(), k = read();
    for (int i = 1; i <= n; ++i){
        a[i] = read();
        ma[a[i]]++;
    }
    ll ans = 0;
    if (ma[0] >= k)
        ma[0] = k;
    for (int i = 1; i <= n; ++i){
        if (ma[i] >= ma[i - 1]) ma[i] = ma[i - 1];
        else{
            ans += 1ll * (ma[i - 1] - ma[i]) * i;
        }
        if (ma[i] == 0) break;
    }
    cout << ans << "\n";


    return 0;
}
