N-orthotope

No attempts yetTime limit1sMemory limit256 MB

Problem

An axis parallel N-orthotope is the set of N dimensional points written in this form.

[s1,e1]×[s2,e2]××[sN,eN](si<ei)[s_1, e_1] \times [s_2, e_2] \times \cdots \times [s_N, e_N] \quad (s_i < e_i)

That is, it collects every point (x1,x2,,xN)(x_1, x_2, \ldots, x_N) whose coordinate xix_i satisfies sixieis_i \le x_i \le e_i.

  • For N=0N = 0 the set is defined as a point in 0 dimensions.
  • For N=1N = 1 it is a segment on a line.
  • For N=2N = 2 it is an axis parallel rectangular region in the plane.
  • For N=3N = 3 it is an axis parallel rectangular box in space.

Generalize a little and allow sieis_i \le e_i in the product

[s1,e1]×[s2,e2]××[sK,eK](siei)[s_1, e_1] \times [s_2, e_2] \times \cdots \times [s_K, e_K] \quad (s_i \le e_i)

If exactly NN indices satisfy si<eis_i < e_i, this set of points is an axis parallel N-orthotope. The words 'axis parallel' are dropped from here on, but every orthotope below is still axis parallel.

Two N-orthotopes are given for some NN. If some points belong to both regions at once, those points form an M-orthotope. Write a program that computes MM. For 2-orthotopes there are the four cases below.

  • In A the common region is again a 2-orthotope.
  • In B the common region is a 1-orthotope, a segment.
  • In C the common region is a 0-orthotope, a point.
  • In D there is no common region. Print -1 in that case.

Input

The first line has a natural number NN.

The second line has s1,e1,s2,e2,,sN,eNs_1, e_1, s_2, e_2, \ldots, s_N, e_N of the first region, separated by spaces.

The third line has s1,e1,s2,e2,,sN,eNs_1, e_1, s_2, e_2, \ldots, s_N, e_N of the second region, separated by spaces.

Every given number is an integer with absolute value at most 11, and si<eis_i < e_i holds for each ii.

1N111 \le N \le 11.

Output

On the first line print MM if the common region of the two regions is an M-orthotope. If there is no common region, print -1.