#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100
#define INF 1000000005
#define INFLL (ll)1e17
#define ER 1e-10
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = (1<<20);
const int MOD = 998244353;

//ダイクストラ法
struct edge{int to,cost;};
vector<edge>G1[MAX],G2[MAX];
int d1[MAX],d2[MAX];
int prever[MAX];

void dijkstra(int s,int V,int d[MAX],vector<edge>G[MAX]){
    priority_queue<P,vector<P>,greater<P>>que;
    for(int i=0;i<V;i++){
        d[i]=INF;
        prever[i]=-1;
    }
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                prever[e.to]=v;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    int p=n;
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(a==b){
            G1[a].push_back({n,0});
            G1[n].push_back({a,c});
            G2[a].push_back({n,c});
            G2[n].push_back({a,0});
            n++;

        }else{
            G1[a].push_back({b,c});
            G2[b].push_back({a,c});
        }
    }
    REP(i,p){
        dijkstra(i,n,d1,G1);
        dijkstra(i,n,d2,G2);
        int tmp=INF;
        REP(j,n){
            if(i==j||d1[j]==INF||d2[j]==INF)continue;
            tmp=min(tmp,d1[j]+d2[j]);
        }
        if(tmp==INF)OUT(-1);
        else OUT(tmp);

    }
}
int main(){
    solve();
    return 0;
}

#include <bits/stdc++.h>
#define fir first
#define sec second
#define PB push_back
#define MP make_pair

using namespace std;

#define REP(i, _a, _b) for (int (i) = (int)(_a); (i) < (int)(_b); (i)++)
#define REV(i, _b, _a) for (int (i) = (int)(_b) - 1; (i) >= (int)(_a); (i)--)

template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); }
template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); }

typedef long long LL;
typedef pair <int, int> pi;

const int N = 2e5 + 5;

int n, m;

void bad() { printf("-1\n"); exit(0); }

int main(){
    scanf("%d%d", &n, &m);
    if (m < 0) bad();
    if (m == 0){
        REP(i, 0, n) printf("%d %d\n", 2 * i + 1, 2 * i + 2);
        return 0;
    }

    if (n < m + 2) bad();

    int l = 1, r = 2 * n;
    for (int i = 1; i <= n - m - 1; i++, l++, r--) printf("%d %d\n", l, r);
    l--, r++;
    for (int i = 0; i < m + 1; i++) printf("%d %d\n", 2 * i + 1 + l, 2 * i + 2 + l);

    return 0;
}