{"raw_statement":[{"iden":"problem statement","content":"You have $N$ sets $S_1, S_2, \\ldots, S_N$. Initially, for each $i$ from $1$ to $N$, set $S_i$ contains only integer $i$ (that is, $S_i = {i}$).\nYou are allowed to perform the following operation:\n\n*   Choose any $i$ with $1 \\le i \\le N-1$. Let $U = S_i \\cup S_{i+1}$ ー the union of sets $S_i$ and $S_{i+1}$. Then, replace both $S_i$ and $S_{i+1}$ with $U$.\n\nYou want to perform a finite number of operations above (maybe zero), to get a configuration, in which $S_i = {L_i, L_i+1, \\ldots, R_i-1, R_i}$ for all $i$ from $1$ to $N$. Is it possible to reach this configuration? If it is possible, also find the smallest number of operations needed to reach it."},{"iden":"constraints","content":"*   $1 \\le N \\le 5\\cdot 10^5$\n*   $1 \\le L_i \\le R_i \\le N$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$L_1$ $R_1$\n$L_2$ $R_2$\n$\\vdots$\n$L_N$ $R_N$"},{"iden":"sample input 1","content":"3\n1 2\n1 2\n1 3"},{"iden":"sample output 1","content":"\\-1\n\nIt can be proved that it's impossible to obtain the required configuration."},{"iden":"sample input 2","content":"4\n1 3\n1 4\n1 4\n2 4"},{"iden":"sample output 2","content":"4\n\nWe can perform the following sequence of operations:\n\n*   Choose $i = 2$, get $S_1 = {1}, S_2 = {2, 3}, S_3 = {2, 3}, S_4 = {4}$\n*   Choose $i = 1$, get $S_1 = {1, 2, 3}, S_2 = {1, 2, 3}, S_3 = {2, 3}, S_4 = {4}$\n*   Choose $i = 3$, get $S_1 = {1, 2, 3}, S_2 = {1, 2, 3}, S_3 = {2, 3, 4}, S_4 = {2, 3, 4}$\n*   Choose $i = 2$, get $S_1 = {1, 2, 3}, S_2 = {1, 2, 3, 4}, S_3 = {1, 2, 3, 4}, S_4 = {2, 3, 4}$"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}