#include int main() { using namespace std; const auto find_shortest_path_cost{ [](const unsigned N, const vector> &edges, unsigned start, unsigned goal) -> optional { constexpr auto inf{numeric_limits::max() / 2}; vector distance(N, inf); distance[start] = 0; for (unsigned j{}; j < 2 * N; j++) for (const auto &[from, to, cost] : edges) if (distance[from] != inf && distance[to] > distance[from] + cost) distance[to] = distance[from] + cost; for (unsigned i{}; i < 2 * N; i++) for (const auto &[from, to, cost] : edges) if (distance[from] != inf && distance[to] > distance[from] + cost) distance[to] = -inf; if (distance[goal] == -inf) return nullopt; return distance[goal]; }}; unsigned N, M; cin >> N >> M; vector A(N); for (auto &a : A) cin >> a; vector> edges(M); for (auto &[a, b, c] : edges) { cin >> a >> b >> c; --a; --b; c = c - A[a]; } if (const auto ans{find_shortest_path_cost(N, edges, 0, N - 1)}; ans) cout << A.back() - *ans << endl; else cout << "inf" << endl; return 0; }