#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e16;

struct BC {
  typedef pair<int, int> P;
  int n;
  vector<vector<int> > G, C, T;
  vector<int> ord, low, bel;
  vector<P> B;
  BC() {}
  BC(int sz) : n(sz), G(sz), C(sz), T(sz) {}

  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool is_bridge(int u, int v) {
    if ( ord[u] > ord[v] ) swap(u, v);
    return ord[u] < low[v];    
  }

  void dfs(int v, int p, int &k) {
    ord[v] = low[v] = k;
    k++;
    for ( int u : G[v] ) {
      if ( u == p ) continue;
      if ( ord[u] >= 0 ) {
	low[v] = min(low[v], ord[u]);
      } else {
	dfs(u, v, k);
	low[v] = min(low[v], low[u]);
      }
      if ( is_bridge(u, v) ) B.push_back(P(u, v));      
    }
  }

  void fill_component(int c, int v) {
    C[c].push_back(v);
    bel[v] = c;
    for ( int u : G[v] ) {
      if ( bel[u] >= 0 || is_bridge(u, v) ) continue;
      fill_component(c, u);      
    }
  }

  void add_component(int v, int &k) {
    if ( bel[v] >= 0 ) return;
    fill_component(k++, v);    
  }

  int build() {
    int k = 0;
    ord.resize(n);
    low.resize(n);
    bel.resize(n);
    fill(ord.begin(), ord.end(), -1);
    fill(bel.begin(), bel.end(), -1);
    for ( int v = 0; v < n; v++ ) {
      if ( ord[v] >= 0 ) continue;
      dfs(v, -1, k);
    }
    k = 0;
    for ( int i = 0; i < (int)B.size(); i++ ) {
      add_component(B[i].first, k);
      add_component(B[i].second, k);
    }
    for ( int v = 0; v < n; v++ ) add_component(v, k);
    for ( int i = 0; i < (int)B.size(); i++ ) {
      int u = bel[B[i].first], v = bel[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
    return k;    
  }
};

struct Edge {
  int u, v, w;
};

int N, M;
vector<Edge> G;
vector<int> sum;
vector<int> sub;
vector<vector<int> > T;
int t;
vector<int> bel;
map<int, int> cost[100001];

int calc_sum(int u, int p) {
  int ret = sum[u];
  for ( int v : T[u] ) {
    if ( v == p ) continue;   
    ret += cost[u][v];
    ret += calc_sum(v, u);    
  }

  return sub[u] = ret;  
}

signed main() {
  cin >> N >> M;
  pair<int, int> ans = {INF, INF};

  BC bc(N);
  for ( int i = 0; i < M; i++ ) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    bc.add_edge(u, v);
    G.push_back(Edge{u, v, w});    
  }

  t = bc.build();
  T = bc.T;
  bel = bc.bel;  
  
  sum = sub = vector<int>(N, 0);

  for ( int i = 0; i < M; i++ ) {
    int u = G[i].u, v = G[i].v, w = G[i].w;    
    if ( bel[u] == bel[v] ) {
      sum[bel[u]] += w;
    } else {
      cost[bel[u]][bel[v]] += w;
      cost[bel[v]][bel[u]] += w;      
    }
  }

  calc_sum(0, -1);

  int mi = INF;  
  int all = sub[0];
  for ( int i = 0; i < M; i++ ) {
    int u = G[i].u, v = G[i].v, w = G[i].w;
    if ( mi > all-w ) {
      mi = all-w;
      ans = {u, v};      
    } else if ( mi == all-w ) {
      ans = min(ans, {u, v});      
    }
    if ( bel[u] == bel[v] ) continue;
    int ab = abs((all-(min(sub[bel[u]], sub[bel[v]]))-w) - min(sub[bel[u]], sub[bel[v]]));    
    if ( mi > ab ) {
      mi = ab;      
      ans = {u, v};      
    } else if ( mi == ab ) {
      ans = min(ans, {u, v});
    }
  }

  cout << ans.first+1 << " " << ans.second+1 << endl;  
  
  return 0;
}



Measured memory_bytes: 51648