{"raw_statement":[{"iden":"problem statement","content":"You are given a directed graph $G$ with $N$ vertices and $M$ edges. The vertices are numbered $1, 2, \\ldots, N$. The $i$\\-th edge is directed from Vertex $a_i$ to Vertex $b_i$, where $a_i < b_i$.\nThe **beautifulness** of a sequence of positive integers $W = (W_1, W_2, \\ldots, W_N)$ is defined as the maximum positive integer $x$ that satisfies the following:\n\n*   For every path $(v_1, \\ldots, v_k)$ ($v_1 = 1, v_k = N$) from Vertex $1$ to Vertex $N$ in $G$, $\\sum_{i=1}^k W_{v_i}$ is a multiple of $x$.\n\nYou are given an integer sequence $A = (A_1, A_2, \\ldots, A_N)$. Find the maximum beautifulness of a sequence of positive integers $W = (W_1, \\ldots, W_N)$ such that $A_i \\neq -1 \\implies W_i = A_i$. If the maximum beautifulness does not exist, print `-1`."},{"iden":"constraints","content":"*   $2\\leq N\\leq 3\\times 10^5$\n*   $1\\leq M\\leq 3\\times 10^5$\n*   $1\\leq a_i < b_i \\leq N$\n*   $(a_i,b_i)\\neq (a_j,b_j)$ if $i\\neq j$\n*   In the given graph $G$, there is a path from Vertex $1$ to Vertex $N$.\n*   $A_i = -1$ or $1\\leq A_i\\leq 10^{12}$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $M$\n$a_1$ $b_1$\n$\\vdots$\n$a_M$ $b_M$\n$A_1$ $A_2$ $\\ldots$ $A_N$"},{"iden":"sample input 1","content":"4 4\n1 2\n1 3\n2 4\n3 4\n-1 3 7 -1"},{"iden":"sample output 1","content":"4\n\nThere are two paths from Vertex $1$ to Vertex $N$: $(1,2,4)$ and $(1,3,4)$. For instance, $W = (5, 3, 7, 8)$ has a beautifulness of $4$. Indeed, both $W_1 + W_2 + W_4 = 16$ and $W_1 + W_3 + W_4 = 20$ are multiples of $4$."},{"iden":"sample input 2","content":"4 5\n1 2\n1 3\n2 4\n3 4\n1 4\n-1 3 7 -1"},{"iden":"sample output 2","content":"1\n\nThere are three paths from Vertex $1$ to Vertex $N$: $(1,2,4)$, $(1,3,4)$, and $(1,4)$. For instance, $W = (5, 3, 7, 8)$ has a beautifulness of $1$."},{"iden":"sample input 3","content":"4 4\n1 2\n1 3\n2 4\n3 4\n3 -1 -1 7"},{"iden":"sample output 3","content":"\\-1\n\nFor instance, $W = (3, 10^{100}, 10^{100}, 7)$ has a beautifulness of $10^{100}+10$. Since you can increase the beautifulness of $W$ as much as you want, there is no maximum beautifulness."},{"iden":"sample input 4","content":"5 5\n1 3\n3 5\n2 3\n3 4\n1 4\n2 -1 3 -1 4"},{"iden":"sample output 4","content":"9"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}