""" 最初に持つ数は 1 1 x でいい 交換も一番小さいのと大きいのでいい にぶたん """ from heapq import* n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges[v].append(u) tot = [0] * n max_ = [0] * n for i in range(n): a, b, c = map(int, input().split()) tot[i] = a + b + c max_[i] = max(a, b, c) def ok(x): hq = [(tot[0], 0)] used = [False] * n used[0] = True a, b, c = x, 1, 1 while hq: t, pos = heappop(hq) if t >= a + b + c: return False for npos in edges[pos]: if not used[npos]: used[npos] = True heappush(hq, (tot[npos], npos)) ma = max_[npos] if ma > c: c = ma if c > b: b, c = c, b if b > a: a, b = b, a return True l = 1 r = 3 * 10 ** 8 while r - l > 1: mid = (l + r) // 2 if ok(mid): r = mid else: l = mid print(1, 1, r)