import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int[] values = new int[n]; List> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { graph.get(sc.nextInt() - 1).add(new Path(sc.nextInt() - 1, sc.nextInt())); } PriorityQueue queue = new PriorityQueue<>(); long[] points = new long[n]; Arrays.fill(points, Long.MIN_VALUE); queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (p.value < Long.MAX_VALUE) { p.value += values[p.idx]; } if (points[p.idx] >= p.value) { continue; } if (points[p.idx] > Long.MIN_VALUE) { p.value = Long.MAX_VALUE; } points[p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, p.value - (p.value == Long.MAX_VALUE ? 0 : x.value))); } } System.out.println(points[n - 1] == Long.MAX_VALUE ? "inf" : points[n - 1]); } static class Path implements Comparable { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return Long.compare(another.value, value); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }