#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

using pint = pair<int,int>;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge> >;
Graph G;

long long all = 0;
long long res = 1LL<<60;
pint res_e = pint(1<<29, 1<<29);

struct LowLink {
    // main results
    vector<int> aps; // articulation points
    vector<pair<int,int> > brs; // brideges
    
    // intermediate results
    vector<int> seen, ord, low;

    // dp
    vector<long long> val;
    
    void dfs_lowlink(const Graph &G, int v, int p = -1) {
        static int time = 0;
        seen[v] = true;
        ord[v] = low[v] = time++;
        int num_of_child = 0;
        bool exist = false; // for articulation point
        for (auto e : G[v]) {
            int ch = e.first;
            long long w = e.second;
            if (seen[ch]) {
                if (ch != p) low[v] = min(low[v], ord[ch]), val[v] += w; // back edge
                continue;
            }
            dfs_lowlink(G, ch, v);
            val[v] += w + val[ch];
            low[v] = min(low[v], low[ch]); // forward edge of DFS-tree
            if (ord[v] < low[ch]) {
                brs.emplace_back(v, ch);
                long long diff = abs(val[ch] - (all - w - val[ch]));
				//cout << v << ", " << ch << ": " << val[ch] << ";; " << diff << endl;
				if (chmin(res, diff))
					res_e = pint(min(v, ch), max(v, ch));
				else if (res == diff)
					chmin(res_e, pint(min(v, ch), max(v, ch)));
            }
            if (ord[v] <= low[ch]) exist = true;
            ++num_of_child;
        }
        //cout << v << ": " << val[v] << endl;
        if ((p == -1 && num_of_child > 1) || (p != -1 && exist)) aps.emplace_back(v);
    }
    void solve(const Graph &G) {
        int N = (int)G.size();
        seen.assign(N, 0); ord.resize(N); low.resize(N); val.assign(N, 0);
        aps.clear(); brs.clear();
        for (int v = 0; v < N; ++v) if (!seen[v]) dfs_lowlink(G, v);
    }
};

int main() {
    int N, M; cin >> N >> M;
    G.clear(); G.resize(N);
    for (int i = 0; i < M; ++i) {
        int u, v; long long w; cin >> u >> v >> w; --u, --v;
        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
        all += w;
    }
    for (int v = 0; v < N; ++v) {
        for (auto e : G[v]) {
			if (chmin(res, all - e.second))
				res_e = pint(min(v, e.first), max(v, e.first));
			else if (res == all - e.second)
				chmin(res_e, pint(min(v, e.first), max(v, e.first)));
        }
    }
    LowLink ll;
    ll.solve(G);
    cout << res_e.first+1 << " " << res_e.second+1 << endl;
}

