#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{
int x,y,z;
} edge[100001];
int n,m,l,r,mid,ans,f[301];
bool cmp(node a,node b)
{
return a.z<b.z;
}
int find(int i)
{
if (f[i]==i) return i;
f[i]=find(f[i]);
return f[i];
}
bool search(int x)
{
int p,q;
for (int i=1;i<=n;i++) f[i]=i;
for (int i=1;i<=x;i++)
{
p=find(edge[i].x);
q=find(edge[i].y);
if (p!=q) f[p]=q;
}
for (int i=2;i<=n;i++) if (find(i)!=find(i-1)) return false; //判断是否在一个根上。
return true;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].z);
sort(edge+1,edge+m+1,cmp);
l=1;r=m;
while (l<=r)
{
mid=(l+r)/2;
if (search(mid)) { ans=edge[mid].z; r=mid-1; } else l=mid+1; //二分 记录当前答案。
}
printf("%d %d",n-1,ans);
return 0;
}