'''
直接求克鲁斯卡尔最后加入连通分量的边的长度即可
'''
class MergeSet:
def __init__(self):
self.m = {}
self.__root_cnt = 0
def getRoot(self, node):
root = node
buf = []
while self.m[root] != root:
buf.append(root)
root = self.m[root]
for node in buf:
self.m[node] = root
return root
def merge(self, a, b):
for node in [a, b]:
if node not in self.m:
self.m[node] = node
self.__root_cnt += 1
root1 = self.getRoot(a)
root2 = self.getRoot(b)
if root1 != root2:
self.m[root1] = root2
self.__root_cnt -= 1
def isInSameSet(self, a, b):
if a == b:
return True
for node in [a, b]:
if node not in self.m:
return False
return self.getRoot(a) == self.getRoot(b)
def getRootNum(self):
return self.__root_cnt
def getClusters(self):
rec = {}
for node in self.m:
root = self.getRoot(node)
if root not in rec:
rec[root] = []
rec[root].append(node)
return [nodes for nodes in rec.values()]
def getMinSpanTreeKruscalMaxEdgeLen(edges):
if len(edges) == 0:
return [None, None]
edge_list = [(w, a, b) for a, b, w in edges]
edge_list.sort()
merge_set = MergeSet()
span_tree = []
node_set = set()
for a, b, _ in edges:
node_set.add(a)
node_set.add(b)
sum = 0
max_len = -1
for w, a, b in edge_list:
if merge_set.isInSameSet(a, b):
continue
merge_set.merge(a, b)
span_tree.append((a, b))
sum += w
if len(span_tree) == len(node_set) - 1:
max_len = w
break
return max_len
edges = []
n, m = map(int, input().split())
for i in range(m):
a, b, w = map(int, input().split())
edges.append((a, b, w))
print(n-1, getMinSpanTreeKruscalMaxEdgeLen(edges))