#include <bits/stdc++.h>
#include <math.h>

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
    int a,b;
  cin>>a>>b;
  for(int i=-1000;i<=1000;i++){
    for(int j=-1000;j<=1000;j++){
    if(i+j==a && i-j==b){
      cout<<i<<" "<<j<<endl;
      return 0;
      }
  }
  }
    
    return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
    if(p==0) return 1;
    if(p%2==0){
        long long a=modpow(n,p/2,mod);
        return a*a%mod;
    }
    if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
    cerr<<"ERROR"<<endl;
    return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
    return modpow(n,mod-2,mod);
}

template<typename T>
bool chmax(T &a,const T &b){
    if(a<b){
        a=b;
        return 1;
    }
    return 0;
}

template<typename T>
bool chmin(T &a,const T &b){
    if(a>b){
        a=b;
        return 1;
    }
    return 0;
}




#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N, M;
vector<pair<int, int> > G[2011];

LL D[2011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, M) {
	int x, y, c;
	scanf("%d%d%d", &x, &y, &c);
	x--; y--;
	G[x].emplace_back(y, c);
    }

    REP (s, N) {
	memset(D, 0x3f, sizeof D);
	const int INF = D[0];
	D[s] = 0;
	priority_queue<pair<LL, int> > Q;
	Q.emplace(0, s);
	while (!Q.empty()) {
	    int v = Q.top().second;
	    LL cst = -Q.top().first;
	    Q.pop();
	    if (cst != D[v]) continue;

	    EACH (e, G[v]) {
		int w = e->first;
		LL tmp = cst + e->second;
		if (D[w] > tmp) {
		    D[w] = tmp;
		    Q.emplace(-tmp, w);
		}
	    }
	}

	LL ans = INF;
	REP (v, N) EACH (e, G[v]) {
	    int w = e->first;
	    int c = e->second;
	    if (w == s) amin(ans, D[v] + c);
	}

	if (ans == INF) puts("-1");
	else printf("%lld\n", ans);

    }

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

