#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;
int a[500][500],jl1,jl2,n,m;
int main(){
freopen("djsb.in","r",stdin);
freopen("djsb.out","w",stdout);
cin>>n>>m;
for (int i=0;i<=n-1;++i)
for (int j=0;j<=n-1;++j)
a[i][j]=10000000;
for (int i=1;i<=m;++i)
{
int x,y,z;
cin>>x>>y>>z;
a[x][y]=a[y][x]=z;
}
for (int k=0;k<=n-1;++k)
for (int i=0;i<=n-1;++i)
if (i!=k)
for (int j=0;j<=n-1;++j)
if (i!=j)
if (a[i][k]+a[k][j]<a[i][j]) a[i][j]=a[i][k]+a[k][j];
int ma[500][500];
for (int i=0;i<=n-1;++i)
for (int j=0;j<=n-1;++j)
if (i!=j) {
ma[i][j]=-1000000;}
int zmax=100000000;
for (int i=0;i<=n-1;++i)
for (int j=0;j<=n-1;++j)
if (i!=j)
for (int k=0;k<=n-1;++k)
if (k!=i&&k!=j)
ma[i][j]=max(ma[i][j],min(a[k][i],a[k][j]));
/*for (int i=0;i<=n-1;++i)
{
for (int j=0;j<=n-1;++j)
if (i!=j) cout<<ma[i][j]<<" ";
cout<<endl;
}*/
for (int i=0;i<=n-1;++i)
for (int j=0;j<=n-1;++j)
if (i!=j&&ma[i][j]<zmax&&ma[i][j]>-1000000)
{
zmax=ma[i][j];
jl1=i;
jl2=j;
}
if (jl1>jl2) cout<<jl2<<" "<<jl1;
else cout<<jl1<<" "<<jl2;
return 0;
}