import heapq def solve(n, m, graph, abc): for i in range(n): abc[i].sort(reverse=True) ans = sum(abc[0]) - 1 myabc = [ans, 1, 1] myabc[1] = abc[0][0] v = graph[0][0] for to in graph[0]: if sum(abc[to]) < sum(abc[v]): v = to if sum(abc[v]) >= sum(myabc): ans += sum(abc[v]) - sum(myabc) + 1 myabc = [ans, 1, 1] q, visit = [], [False] * n heapq.heappush(q, (sum(abc[0]), 0)) visit[0] = True while q: nowsum, now = heapq.heappop(q) if nowsum >= sum(myabc): diff = nowsum - sum(myabc) + 1 if myabc[0] == ans: ans += diff myabc[0] += diff elif myabc[1] == ans: ans += diff myabc[1] += diff elif myabc[2] == ans: ans += diff myabc[2] += diff else: ans = myabc[2] + diff myabc[2] += diff if now == n - 1: return ans, 1, 1 myabc += abc[now] myabc.sort(reverse=True) myabc = myabc[:3] for to in graph[now]: if visit[to]: continue visit[to] = True heapq.heappush(q, (sum(abc[to]), to)) if __name__ == '__main__': n, m = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 graph[u].append(v) graph[v].append(u) abc = [list(map(int, input().split())) for _ in range(n)] a, b, c = solve(n, m, graph, abc) print(a, b, c)