#include<bits/stdc++.h>
#define ss second
#define ff first
#define pb push_back
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=2e5+10;

int main(){

    ///freopen("test.txt","r",stdin);

    int n,m;
   scanf("%d %d",&n,&m);
   if(n==1 && m==0){
    printf("1 2\n");
    return 0;
   }
   if(m<0 || m==n || m==n-1){
    printf("-1\n");
    return 0;
   }
   if(n==1 && m!=0){
        printf("-1\n");
        return 0;
   }

   vector<pii>rez;
   for(int i=1;i<n;i++)rez.pb({i*3+1,i*3+3});

   rez.pb({1,rez[m].ff+1});

   for(int i=0;i<rez.size();i++)printf("%d %d\n",rez[i].ff,rez[i].ss);


return 0;
}



//Shrey Dubey


#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<list>
#include<iomanip>
#include<queue>
#include<stack>
#include <math.h>
#include<climits>
#include<bitset>
#include<cstring>
#include<numeric>
#include<array>


using namespace std;
typedef long long ll;
typedef long double ld;

#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers
#define pb push_back
#define ff first
#define sec second
#define umap unordered_map
#define mp make_pair
#define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fo(n) for(ll i = 0; i<n; i++)
#define fnd(stl, data) find(stl.begin(), stl.end(), data)
#define forn(x,n) for(ll x = 0; x<n; x++)
#define imax INT_MAX
#define lmax LLONG_MAX
#define imin INT_MIN
#define lmin LLONG_MIN
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<ll,ll> >
#define vb vector<bool>
#define pr(t) cout<<t<<"\n"
#define int long long
#define ql queue<ll>
#define qp queue<pair<ll,ll> >
#define endl "\n"
#define nl cout<<"\n"
#define re cin >>
#define pll pair<ll,ll>
#define FOR(a,b) for(ll i = a; i<=b; i++)
#define all(x) x.begin(),x.end()

// ll dx[] = {1,0,-1,0};
// ll dy[] = {0,1,0,-1};

ll mod = 1e9 + 7;

ll cl(ld a){
    if(a>(ll) a){
        return (ll)a+1;
    }
    else{
        return (ll)a;
    }
}

ll flr(ld a){
    if(a < 0.0){
        return (ll) a - 1;
    }
    return (ll) a;
}

//code starts here

const ll M = 2e5+100;
vl gr[M];
ll n,m,x,y;
ll a[M];
ll dp[M];
bool vis[M] = {false};
void dfs(ll cur){
    vis[cur] = true;
    dp[cur] = 0;
    for(auto x: gr[cur]){
        if(!vis[x]){
            dfs(x);
        }
        dp[cur] = max(dp[cur],max(a[x],dp[x]));
    }
}


void solve(){
    re n; re m;
    fo(n) re a[i+1];
    fo(m){
        re x; re y;
        gr[x].pb(y);
    }
    for(ll i = 1; i<=n; i++){
        if(!vis[i]) dfs(i);
    }
    ll ans = -1e15;
    for(ll i = 1; i<=n; i++){
        if(dp[i] != 0){
            ans = max(ans,dp[i]-a[i]);
        }
    }
    pr(ans);
}

int32_t main(){
    KOBE;
    ll t;
    t = 1;
    // re t;
    while(t--) solve();
}


//common errors
// row - n, col - m always and loop var
// see the freq of numbers carefully
// see if there's array overflow
// use map for large inputs


//problem ideas
//check piegonhole wherever possible
//there might be many instances of limited answers like 0,1,2 only
// see suffix and prefix
//don't be obsessed with binary search
// try to find repeating pattern in matrices
