/*  -*- coding: utf-8 -*-
 *
 * 2893.cc: Balanced Edge Deletion
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_GN = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 60;

/* typedef */

typedef long long ll;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef stack<int> si;

struct Edge {
  int i, j, w;
  Edge() {}
  Edge(int _i, int _j, int _w): i(_i), j(_j), w(_w) {}
};

/* global variables */

vpii nbrs[MAX_N], gnbrs[MAX_GN];
Edge es[MAX_M];
int gmap[MAX_N], gps[MAX_GN], gpws[MAX_GN], gcns[MAX_GN];
ll gws[MAX_GN];

/* subroutines */

void bcc_visit(const vpii *nbrs, int v, int u,
	       vpii& brdg, vvi& tecomp,
	       si& roots, si& S, vb& inS, vi& num, int& time) {
  num[v] = ++time;
  S.push(v); inS[v] = true;
  roots.push(v);

  const vpii& nbrv = nbrs[v];
  for (vpii::const_iterator vit = nbrv.begin(); vit != nbrv.end(); vit++) {
    const int& w = vit->first;
    if (num[w] == 0)
      bcc_visit(nbrs, w, v, brdg, tecomp, roots, S, inS, num, time);
    else if (u != w && inS[w])
      while (num[roots.top()] > num[w]) roots.pop();
  }

  if (v == roots.top()) {
    brdg.push_back(pii(u, v));
    tecomp.push_back(vi());
    for (;;) {
      int w = S.top(); S.pop(); inS[w] = false;
      tecomp.back().push_back(w);
      if (v == w) break;
    }
    roots.pop();
  }
}

void calc_bcc(const int n, const vpii *nbrs, vpii& brdg, vvi& tecomp) {
  vi num(n);
  vb inS(n);
  si roots, S;
  int time = 0;

  for (int u = 0; u < n; u++)
    if (num[u] == 0) {
      bcc_visit(nbrs, u, n, brdg, tecomp, roots, S, inS, num, time);
      brdg.pop_back();
    }
}

inline ll absll(ll a) { return (a >= 0) ? a : -a; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  ll wsum = 0;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    nbrs[u].push_back(pii(v, i));
    nbrs[v].push_back(pii(u, i));
    es[i] = Edge(u, v, w);
    wsum += w;
  }

  vpii brdg;
  vvi tecomp;
  calc_bcc(n, nbrs, brdg, tecomp);
  //printf("brdg=%d\n", (int)brdg.size());

  int gn = tecomp.size();
  for (int i = 0; i < gn; i++)
    for (int j = 0; j < tecomp[i].size(); j++)
      gmap[tecomp[i][j]] = i;
  //for (int i = 0; i < n; i++) printf("%d ", gmap[i]); putchar('\n');

  for (int i = 0; i < m; i++) {
    Edge &ei = es[i];
    int &gi = gmap[ei.i], &gj = gmap[ei.j];

    if (gi == gj) gws[gi] += ei.w;
    else {
      gnbrs[gi].push_back(pii(gj, ei.w));
      gnbrs[gj].push_back(pii(gi, ei.w));
    }
  }

  gps[0] = -1, gpws[0] = 0;
  qi q;
  q.push(0);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    int &up = gps[u];
    vpii &gnbru = gnbrs[u];
    for (vpii::iterator vit = gnbru.begin(); vit != gnbru.end(); vit++) {
      int &v = vit->first;
      if (v != up) {
	gps[v] = u, gpws[v] = vit->second;
	gcns[u]++;
	q.push(v);
      }
    }
  }

  for (int i = 0; i < gn; i++)
    if (gcns[i] == 0) q.push(i);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    int &up = gps[u];
    if (up >= 0) {
      gws[up] += gws[u] + gpws[u];
      if (--gcns[up] == 0) q.push(up);
    }
  }

  ll mind = LINF;
  int mini = -1, minj = -1;

  for (int i = 0; i < m; i++) {
    Edge &ei = es[i];
    int &gi = gmap[ei.i], &gj = gmap[ei.j];

    ll d;
    if (gi == gj) 
      d = wsum - ei.w;
    else {
      if (gps[gi] == gj)
	d = absll((wsum - gws[gi] - gpws[gi]) - gws[gi]);
      else
	d = absll((wsum - gws[gj] - gpws[gj]) - gws[gj]);
    }

    if (mind > d ||
	(mind == d && (mini > ei.i || (mini == ei.j && minj > ei.j))))
      mind = d, mini = ei.i, minj = ei.j;
  }

  printf("%d %d\n", mini + 1, minj + 1);
  return 0;
}



Measured memory_bytes: 25064