Bajtazar's confectionery received two urgent orders, each for one cake. As everyone knows, cakes are made of layers. The shop offers n 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 n confectioners. For every i with 1≤i≤n, the i-th confectioner can make a layer of type i. 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.
The first line contains one integer n (1≤n≤106).
The second and third lines describe the first and the second order, respectively. Each description is a sequence of n pairwise distinct integers from 1 to n, listing the types of successive layers of that cake, starting from the layer on top of the cake.
Print one integer: the minimum number of minutes needed to produce the two ordered cakes.