O,R=print,range J=lambda:map(int,input().split()) N,M=J() D=[[]for i in R(N)] E=[] p,h=list(R(N)),[0]*N w=h[:] def r(i): m=p[i] while m!=p[m]: w[i]+=w[m] m=p[i]=p[m] return m for j in R(M): A,B,W=map(int,input().split());A-=1;B-=1 a,b=r(A),r(B) E+=[[A,B,W]] if a==b: if w[A]-w[B]!=W: P,S,F=[j+1],[A],[0]*N while F[B]<1: i=S.pop() for[e,m]in D[i]: if F[e]<1: F[e],p[e]=1,m S+=[e] while A!=B: m=p[B] P+=[m+1] if B==E[m][0]:B,W=E[m][1],W+E[m][2] else:B,W=E[m][0],W-E[m][2] O(len(P)) O(A+1) exit(O(*(P[-1::-1]if W<0else P))) else: W=w[B]+W-w[A] if h[b]