#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(m == 0)
	{
		for(int i=1; i<=n; ++i)
			printf("%d %d\n",2*i-1,2*i);
		return 0;
	}
	if(m<0 || m>=n-1) return printf("-1"), 0;
	
	int cur = 1;
	for(int i=1; i<=m+1; ++i)
		printf("%d %d\n",cur+1,cur+2),
		cur += 2;
	printf("1 %d\n",cur+1);
	++cur;
	
	n -= m+2;
	while(n--)
		printf("%d %d\n",cur+1,cur+2),
		cur += 2;
	return 0;
}
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <numeric> //gcd,lcm c++17
#include <tuple>
#include <iomanip> //setprecision
#include <unordered_map>
#include <chrono>
//#define _GLIBCXX_DEBUG
using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T>
using vv = vc<vc<T>>;
template <typename T>
using PQ = priority_queue<T, vc<T>, greater<T>>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
//typedef __uint128_t Int;
using vi = vc<int>;
using vl = vc<ll>;
using vd = vc<double>;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
#define sz(x) (int)(x).size()
template <class T1, class T2, class Pred = std::less<T2>>
struct sort_pair_second
{
    //sort_pair_second<ll,ll,greater<ll>>()
    bool operator()(const std::pair<T1, T2> &left, const std::pair<T1, T2> &right)
    {
        Pred p;
        return p(left.second, right.second);
    }
};
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int MOD = 1e9 + 7;
double EPS = 1e-9;
int INF = 2000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
int rdx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int rdy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vl A, B;
int N, M;
vi G[200000];
bool visited[200000] = {};
ll sum1, sum2;

void dfs(int v)
{
    visited[v] = true;
    sum1 += A[v];
    sum2 += B[v];
    for (auto x : G[v])
    {
        if (visited[x])
            continue;
        dfs(x);
    }
}

int main()
{
    cin >> N >> M;
    A.resize(N);
    B.resize(N);
    FOR(i, 0, N)
        cin >> A[i];
    FOR(i, 0, N)
        cin >> B[i];
    FOR(i, 0, M)
    {
        int c, d;
        cin >> c >> d;
        c--, d--;
        G[c].push_back(d);
        G[d].push_back(c);
    }
    FOR(i, 0, N)
    {
        if (visited[i])
            continue;
        sum1 = 0, sum2 = 0;
        dfs(i);
        if (sum1 != sum2)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}