Two Cakes

No attempts yetTime limit4sMemory limit128 MB

Problem

Bajtazar's confectionery received two urgent orders, each for one cake. As everyone knows, cakes are made of layers. The shop offers nn different types of layers, and every cake it produces contains exactly one layer of each type. An order specifies the exact order in which the layers must be stacked.

Bajtazar employs nn confectioners. For every ii with 1in1 \le i \le n, the ii-th confectioner can make a layer of type ii. A confectioner needs one minute to make one layer, and during that minute can work on only one cake. The layers of a single cake must be added one after another (a new layer can be started only after the previous layer of that cake is finished). Work on the two cakes may proceed in parallel.

Find the minimum number of minutes needed to produce both ordered cakes.

Input

The first line contains one integer nn (1n1061 \le n \le 10^6).

The second and third lines describe the first and the second order, respectively. Each description is a sequence of nn pairwise distinct integers from 11 to nn, listing the types of successive layers of that cake, starting from the layer on top of the cake.

Output

Print one integer: the minimum number of minutes needed to produce the two ordered cakes.