var
n,m,a,b,i,max:longint;
w:array[1..300,1..300] of longint;
d:array[1..300] of longint;
used:array[1..300] of boolean;
procedure prim(x:longint);
var
i,k,min,pos:longint;
begin
fillchar(used,sizeof(used),false);
used[x]:=true;
for i:=1 to n do
d[i]:=w[x,i];
max:=0;
for k:=1 to n-1 do
begin
min:=maxlongint;
for i:=1 to n do
if (not used[i]) and (d[i]
begin
min:=d[i];
pos:=i;
end;
used[pos]:=true;
if max
max:=d[pos];
for i:=1 to n do
if (not used[i]) and (d[i]>w[pos,i]) then
d[i]:=w[pos,i];
end;
end;
begin
read(n,m);
fillchar(w,sizeof(w),70);
for i:=1 to m do
begin
read(a,b,w[a,b]);
w[b,a]:=w[a,b];
end;
prim(1);
writeln(n-1,' ',max);
end.