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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    UnionFind uf(N);
    while(M--){
        int a, b;
        cin >> a >> b;
        uf.unite(a-1, b-1);
    }
    vector<int64_t> C(N), D(N);
    for(int i=0; i<N; i++){
        int r = uf.find(i);
        C[r] += A[i];
        D[r] += B[i];
    }
    cout << (C==D ? "Yes" : "No") << endl;
    return 0;
}

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &vec)
    {
        for (auto &value : vec)
            is >> value;
        return is;
    }

} 

#include <experimental/optional>

#include <tuple>

namespace asl
{
    typedef long long i64;
    
} 

#include <random>

#include <utility>

#define endl '\n'

using namespace std;
using namespace asl;

vec<int> get_diff(vec<int> &a)
{
    int l = 0;
    vec<int> res(a.size());

    for (int i = 0; i < a.size(); ++i)
    {
        res[i] = a[i] - l - 1;
        l = a[i];
    }
    return res;
}

void solve()
{
    int n, l;
    cin >> n >> l;

    vec<int> a(n), b(n);
    cin >> a >> b;

    a.push_back(l + 1);
    b.push_back(l + 1);

    a = get_diff(a);
    b = get_diff(b);

    i64 answer = 0;

    for (int i = 0, j = 0, k; i <= n; ++i, j = k)
    {
        int s = 0;
        k = j;

        while (s < b[i])
            s += a[k++];

        while (j < k && a[j] == 0)
            ++j;

        if (s > b[i])
        {
            answer = -1;
            break;
        }

        if (b[i] > 0)
        {
            int cur = max(i - j, 0) + max(k - 1 - i, 0);
            answer += cur;
            
        }
    }

    cout << answer << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}


