Chocolate
Chocolate bars produced by the confectionery company «Yum Yum» are designed as long 1×N bars, each consisting of N squares. Each square displays one of N renowned confectioners. On different bars, these same N confectioners appear in varying sequences.
**Task.** Develop a program that, given the sequence of portraits on two chocolate bars, calculates the minimum number of segments the first bar needs to be divided into so that, by rearranging these segments, the sequence on the second bar can be achieved. The bar can only be broken at the edges of the squares, and neither the bar nor its segments can be flipped.
**Input Data.** The first line of the input contains a natural number N (2 ≤ N ≤ 10^5), representing the number of squares in the chocolate bar. Each confectioner is numbered from 1 to N. The second and third lines contain N distinct natural numbers (each not exceeding N) — representing the order of portraits on the first and second bars, respectively. It is guaranteed that these sequences are different.
**Output Data.** The output should be a single number — the minimum number of segments into which the first bar must be broken so that, by rearranging these segments, the sequence of portraits on the second bar can be achieved.
**Evaluation.** The test set is divided into 4 blocks, each with specific conditions:
- 20 points: 2 ≤ N ≤ 3. - 20 points: 3 < N ≤ 6. - 30 points: 6 < N ≤ 1000. - 30 points: 1000 < N ≤ 10^5.
**Explanation.** The first bar can be divided into four segments: square 4, square 3, two squares 2 and 5, and square 1. By rearranging these segments, the sequence of portraits on the second bar can be matched. No division into three or fewer segments will allow the formation of the same sequence as on the second bar.