{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"There are n people in a circle, numbered from \u003cspan class\u003d\"tex_span\"\u003e\u003ci\u003e1\u003c/i\u003e\u003cspan\u003e to \u003cspan class\u003d\"tex_span\"\u003e\u003ci\u003en\u003c/i\u003e\u003cspan\u003e, each of whom always tells the truth or always lies.\nEach person \u003cspan class\u003d\"tex_span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003cspan\u003e makes a claim of the form: “the number of truth-tellers in this circle is between \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\nand bi, inclusive.”\nCompute the maximum number of people who could be telling the truth."}},{"title":"Input","value":{"format":"MD","content":"The first line contains a single integer n (\u003cspan class\u003d\"tex-span\"\u003e0 ≤ \u003ci\u003en\u003c/i\u003e\u003c/sub\u003e ≤ 10\u003csup class\u003d\"upper-index\"\u003e9\u003c/sup\u003e\u003c/span\u003e). Each of the next n lines contains two\nspace-separated integers ai and bi (0 ≤ ai ≤ bi ≤ 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"}}]}