#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxm=50010;
int n,m,a[maxm],maxx,head[2*maxm],fa[310],v[2*maxm],nxt[2*maxm],cnt,w[2*maxm];
int find(int x){
return fa[x]==x?fa[x]:fa[x]=find(fa[x]);
}
struct edge{
int u,v,c;
}s[maxm];
inline int read(){
int num=0; char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
bool cmp(edge a,edge b){
return a.c<b.c;
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;i++){
s[i].u=read(),s[i].v=read(),s[i].c=read();
}
sort(s+1,s+1+m,cmp);
for(int i=1;i<=n;i++) fa[i]=i;
int res=0;
for(int i=1;i<=m;i++){
int fx=find(s[i].u),fy=find(s[i].v);
if(fx==fy) continue;
fa[fx]=fy;
++res;
if(res==n-1){
maxx=s[i].c;
break;
}
}
cout<<n-1<<' '<<maxx<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxm=50010;
int n,m,a[maxm],maxx,head[2*maxm],fa[310],v[2*maxm],nxt[2*maxm],cnt,w[2*maxm];
int find(int x){
return fa[x]==x?fa[x]:fa[x]=find(fa[x]);
}
struct edge{
int u,v,c;
}s[maxm];
inline int read(){
int num=0; char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
bool cmp(edge a,edge b){
return a.c<b.c;
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;i++){
s[i].u=read(),s[i].v=read(),s[i].c=read();
}
sort(s+1,s+1+m,cmp);
for(int i=1;i<=n;i++) fa[i]=i;
int res=0;
for(int i=1;i<=m;i++){
int fx=find(s[i].u),fy=find(s[i].v);
if(fx==fy) continue;
fa[fx]=fy;
++res;
if(res==n-1){
maxx=s[i].c;
break;
}
}
cout<<n-1<<' '<<maxx<<endl;
return 0;
}