#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 2e5 + 10;
pii a[maxn];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; ++i) scanf("%d%d", &a[i].first, &a[i].second);
	sort(a + 1, a + k + 1);
	unordered_set<int> s;
	s.insert(n);
	int j = 1;
	for(int i = 1; i <= k; i = j)
	{
		vector<int> toInsert;
		vector<int> toErase;
		while(a[j].first == a[i].first)
		{
			if(s.count(a[j].second - 1) || s.count(a[j].second + 1))
				toInsert.push_back(a[j].second);
			else toErase.push_back(a[j].second);
			++j;
		}
		for(auto v : toInsert) s.insert(v);
		for(auto v : toErase) s.erase(v);
	}
	printf("%d\n", s.size());		
	return 0;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> a(N), b(N); cin >> a >> b;

  UnionFindTree tree(N);
  for (int i = 0; i < M; ++i) {
    int c, d; cin >> c >> d;
    --c; --d;
    tree.Unite(c, d);
  }

  map<int, vector<int>> sets;
  for (int i = 0; i < N; ++i) sets[tree.Root(i)].push_back(i);

  for (auto [index, v] : sets) {
    LL as = 0, bs = 0;
    for (LL x : v) {
      as += a[x];
      bs += b[x];
    }

    if (as != bs) {
      cout << "No" << endl;
      return 0;
    } else {
      continue;
    }
  }
  cout << "Yes" << endl;
}
