import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } Card[] cards = new Card[n]; for (int i = 0; i < n; i++) { cards[i] = new Card(i, sc.nextInt(), sc.nextInt(), sc.nextInt()); } int left = 0; int right = Integer.MAX_VALUE / 2; PriorityQueue queue = new PriorityQueue<>(); while (right - left > 1) { int x = (left + right) / 2; Card current = new Card(-1, 1, 1, x); queue.clear(); queue.add(cards[0]); boolean[] visited = new boolean[n]; boolean[] added = new boolean[n]; added[0] = true; while (queue.size() > 0 && current.getSum() > queue.peek().getSum() && !visited[n - 1]) { Card c = queue.poll(); if (visited[c.idx]) { continue; } visited[c.idx] = true; current.exchange(c); for (int y : graph.get(c.idx)) { if (!added[y]) { queue.add(cards[y]); added[y] = true; } } } if (visited[n - 1]) { right = x; } else { left = x; } } System.out.println("1 1 " + right); } static class Card implements Comparable { int idx; int[] values; public Card(int idx, int a, int b, int c) { this.idx = idx; values = new int[]{a, b, c}; sort(); } public void sort() { Arrays.sort(values); } public int getSum() { int sum = 0; for (int x : values) { sum += x; } return sum; } public int compareTo(Card another) { return getSum() - another.getSum(); } public void exchange(Card another) { if (values[0] < another.values[2]) { values[0] = another.values[2]; sort(); } } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }