#include // #include // #include using namespace std; // using namespace atcoder; // using bint = boost::multiprecision::cpp_int; using ll = long long; using ull = unsigned long long; using P = pair; using vi = vector; using vvi = vector; using vvvi = vector; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define sz(c) ((ll)(c).size()) #define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin()) // #define MOD 1000000007 #define MOD 998244353 templateusing min_priority_queue=priority_queue,greater>; templateostream&operator<<(ostream&os,vector&v){for(int i = 0;i < v.size();i++)os<istream&operator>>(istream&is,vector&v){for(T&in:v)is>>in;return is;} templateostream&operator<<(ostream&os,pair&p){os<istream&operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} int main(){ ios_base::sync_with_stdio(0), cin.tie(0); ll n,m; cin >> n >> m; vi a(n);cin >> a; vvi v(m+n,vi(3)); rep(i,m){ cin >> v[i]; v[i][0]--;v[i][1]--; v[i][0] += n; } rep(i,n){ v[i+m][0] = i; v[i+m][1] = i+n; v[i+m][2] = -a[i]; } const ll inf = 1ll << 50; vi d(2*n,inf); d[0] = 0; rep(i,2*n-1)rep(j,n+m){ ll fr = v[j][0],to = v[j][1],c = v[j][2]; // if(fr == n-1 && to != 2*n-1)continue; if(d[to] <= d[fr]+c)continue; d[to] = d[fr] + c; } ll D = d[2*n-1]; rep(i,2*n-1)rep(j,n+m){ ll fr = v[j][0],to = v[j][1],c = v[j][2]; // if(fr == n-1 && to != 2*n-1)continue; if(d[to] <= d[fr]+c)continue; d[to] = d[fr] + c; } if(d[2*n-1] < D){ cout << "inf\n"; }else cout << -d[2*n-1] << "\n"; return 0; }