#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> &a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
template<class T>void prArr(T a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Bridges{
public:
  typedef pair<Int,Int> P;
  Int V;
  vector<vector<Int> > G;
  set<P> bridges;
  vector<Int> ord;
  vector<Int> low;

  Bridges(){V = -1;};
  Bridges(Int V):V(V),G(V), ord(V), low(V){}
  
  void add_edge(Int a,Int b){
    assert(a < V && b < V);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  void dfs(Int u,Int p,Int &c){
    ord[u] = low[u] = c++;

    for(Int v:G[u]){
      if(v == p) continue;
      if(ord[v] == -1){
	dfs(v, u, c);
	low[u] = min(low[u], low[v]);
      }
      else low[u] = min(low[u], low[v]);
      if(ord[u] < low[v]) bridges.insert(P(min(u, v), max(u,v)));
    }
  }

  void bridge(){
    assert(V >= 0);
    bridges.clear();
    Int c = 0;
    ord.clear(); ord.resize(V, -1);
    low.clear(); low.resize(V, -1);
    for(Int i=0;i<V;i++) if(ord[i] == -1) dfs(i, -1, c);
  }
  bool isBridge(Int u, Int v){return bridges.count(P(u, v))|| bridges.count(P(v, u));}
};

class BCC{
public:
  Int V;
  Int K;
  Bridges B;
  vector<vector<Int> > G;
  vector<vector<Int> > T;
  vector<Int> par;
  vector<Int> cmp;
  vector<Int> used;

  BCC():V(-1){}
  BCC(Int V):V(V), B(V), G(V){}

  void add_edge(Int a,Int b){
    B.add_edge(a, b);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  void dfs(Int pos){
    if(used[pos]++) return;
    cmp[pos] = K;
    for(Int nx:G[pos]) if(!B.isBridge(pos, nx)) dfs(nx);
  }

  Int bcc(bool makeT = 0){
    B.bridge();
    used.clear(); used.resize(V, 0);
    cmp.clear(); cmp.resize(V, 0);
    K = 0;
    for(Int i=0;i<V;i++) if(used[i] == 0) dfs(i), K++;
    if(makeT) makeTree();
    return K;
  }

  void makeTree(Int pos = -1, Int pre = -1){
    if(pos == -1){
      T.clear(); T.resize(K);
      par.clear();par.resize(K);
      for(Int i=0;i<V;i++){
	set<Int> used;
	for(Int nx:G[i]){
	  Int a = cmp[i], b = cmp[nx];
	  if(a != b && !used.count(b)) T[a].push_back(cmp[nx]), used.insert(b); 
	}
      }
      for(Int i=0;i<K;i++) if(par[i] == -1) makeTree(i, -1);
      return;
    }
    par[pos] = pre;
    for(Int nx:T[pos]) if(nx != pre) makeTree(nx, pos);
  }
};

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;

  vector<vector<P> > G(N);
  BCC bcc(N);
  Int all = 0;

  map<P,Int> ecost;
  for(Int i=0;i<M;i++){
    Int a, b, c;
    cin>>a>>b>>c; a--, b--;
    bcc.add_edge(a, b);
    G[a].push_back(P(b, c));
    G[b].push_back(P(a, c));
    ecost[P(a, b)] = c;
    ecost[P(b, a)] = c;
    all += c;
  }

  using Tu = tuple<Int,Int,Int>;
  Tu ans = Tu(INF, 0, 1);

  for(int i=0;i<N;i++)
    for(P p:G[i]){
      int to = p.first;
      int cost = p.second;
      if(i > to) continue;
      ans = min(ans, Tu(all - cost, i, to));
    }
  

  Int n = bcc.bcc(1);
  vector<Int> sum(n);

  using T = tuple<Int,Int,Int,Int> ;
  set<T> bedge;
  for(Int i=0;i<N;i++)
    for(auto p:G[i]){
      Int to, cost; tie(to, cost) = p;
      if(i > to) continue;
      if(bcc.cmp[i] != bcc.cmp[to]) {
	bedge.insert(T(bcc.cmp[i], bcc.cmp[to], i, to));
	bedge.insert(T(bcc.cmp[to], bcc.cmp[i], to, i));
      }
      else sum[bcc.cmp[i]] += cost;
    }

  
  
  auto g = bcc.T;
  function<Int(Int,Int)> dfs= [&](Int pos,Int pre){

    Int res = sum[pos];
    
    for(Int to:g[pos]){
      if(to == pre) continue;
      Int a, b, u, v;tie(a, b, u, v) = *bedge.lower_bound(T(pos, to, -1, -1));
      assert(a == pos && to == b);
      Int cost =  ecost[P(u, v)];
      Int s = dfs(to, pos);
      Int t = all - cost - s;
      ans = min(ans, Tu(abs(s - t), min(u, v), max(u, v)));
      res += s + cost;
    }
    return res;
  };

  dfs(0, -1);
  Int val,u, v;
  tie(val, u, v) = ans;
  //cout<<val<<endl;
  cout<<u+1<<" "<<v+1<<endl;

  return 0;
}



Measured memory_bytes: 73040