{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"GUC teams like to play group games before programming contests. One such game is Cult. The game is played by $n$ people in a circle, numbered from 1 to $n$, each of whom always tells the truth or always lies. Each person $i$ makes a claim of the form: \"the number of truth-tellers in this circle is between $a_i$ and $b_i$, inclusive.\" Omar is currently in a game of Cult and wants to know the maximum number of people telling the truth."}},{"title":"Input","value":{"format":"MD","content":"The first line contains a single integer $n$ ($1 \\leq n \\leq 10^3$). Each of the next $n$ lines contains two space-separated integers $a_i$ and $b_i$ ($0 \\leq a_i \\leq b_i \\leq n$)."}},{"title":"Output","value":{"format":"MD","content":"Print, on a single line, the maximum number of people who could be telling the truth. If the given\nset of statements is inconsistent, print -1 instead."}},{"title":"Sample 1","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e\n3\n1 1\n2 3\n2 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e8\n0 1\n1 7\n4 8\n3 7\n1 2\n4 5\n3 7\n1 8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}