#include<iostream>
#include<algorithm>
using namespace std;
struct point{int u,v,c;};
point a[10001];
int father[301],n,m,k,i,j,tot=0,ct=0;
int find(int x){
if(father[x]!=x) father[x]=find(father[x]);
return father[x];
}
void unite(int x,int y){
int fx=find(x);
int fy=find(y);
if(fx!=fy)father[fy]=fx;
}
bool cmp(const point &a,const point &b){
if(a.c<b.c)return true;
else return false; }
int main(){
cin>>n>>m;
for(i=1;i<=m;++i){
cin>>a[i].u>>a[i].v>>a[i].c;
}
for(i=1;i<=n;++i)father[i]=i;
sort(a+1,a+m+1,cmp);
for(i=1;i<=m;++i){
if(find(a[i].u)!=find(a[i].v)){
unite(a[i].u,a[i].v);
tot=a[i].c;
ct++;
}
if(ct==n-1)break;
}
cout<<ct<<" "<<tot;
return 0;
}