In a class, Ania wrote a program which does some work for all integers from $0$ to $n - 1$:
for (int i = 0; i < n; i++) {
work (i);
}
The teacher Petia looked at the program and said that it would work for too long, as the maximum value of $n$ is $10^{9}$.
In response, Ania decided to do the work only for a portion of the numbers. Her new program looks as follows:
for (int i = 0; i < n; i++) {
if (i == x_1) i = y_1;
if (i == x_2) i = y_2;
...
if (i == x_k) i = y_k;
work (i);
}
How many operations does this program perform for the given $n$, and does it terminate at all? The operations we count are assignments (i = 0; i++; i = y\_1; \ldots), comparisons (i < n; i == x\_1; \ldots), and the work itself (work (i)).
The input contains the program written by Ania. It is formatted exactly as shown in the examples: in particular, the opening curly bracket is on the line with for, there is a space in front of every opening round bracket, and the indentation is four spaces. The input does not contain spaces at line ends.
The number of lines with conditionals: $0 \le k \le 10^5$. The constraints on the values: $0 \le x_i, y_i < n \le 10^9$, other than that, the values can be arbitrary. The line with work follows once after all the lines with if.
Print the number of operations that the given program performs. If the program never terminates, print -1.