Professor Phunsuk Wangdu has performed some experiments on rays. The setup for *n* rays is as follows.

There is a rectangular box having exactly *n* holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each hole. The holes are in a straight line.

Professor Wangdu is showing his experiment to his students. He shows that there are cases, when all the rays are intersected by every other ray. A curious student asked the professor: "Sir, there are some groups of rays such that all rays in that group intersect every other ray in that group. Can we determine the number of rays in the largest of such groups?".

Professor Wangdu now is in trouble and knowing your intellect he asks you to help him.
The first line contains *n* (1 ≤ *n* ≤ 10<sup class="upper-index">6</sup>), the number of rays. The second line contains *n* distinct integers. The *i*-th integer *x*<sub class="lower-index">*i*</sub> (1 ≤ *x*<sub class="lower-index">*i*</sub> ≤ *n*) shows that the *x*<sub class="lower-index">*i*</sub>-th ray enters from the *i*-th hole. Similarly, third line contains *n* distinct integers. The *i*-th integer *y*<sub class="lower-index">*i*</sub> (1 ≤ *y*<sub class="lower-index">*i*</sub> ≤ *n*) shows that the *y*<sub class="lower-index">*i*</sub>-th ray exits from the *i*-th hole. All rays are numbered from 1 to *n*.
For the first test case, the figure is shown above. The output of the first test case is 3, since the rays number 1, 4 and 3 are the ones which are intersected by each other one i.e. 1 is intersected by 4 and 3, 3 is intersected by 4 and 1, and 4 is intersected by 1 and 3. Hence every ray in this group is intersected by each other one. There does not exist any group containing more than 3 rays satisfying the above-mentioned constraint.
5
1 4 5 2 3
3 4 2 1 5
3
3
3 1 2
2 3 1
2
5
1 2 4 5 3
1 5 4 2 3
3
3
3 1 2
1 3 2
2
7
1 5 2 7 4 3 6
6 3 1 2 5 4 7
4
4
1 4 2 3
2 3 1 4
2
4
2 4 1 3
2 3 1 4
3
10
4 7 8 1 2 3 5 9 6 10
6 3 8 7 10 2 1 4 5 9
5
7
1 5 7 2 4 3 6
3 2 5 7 6 1 4
4
9
1 7 4 9 3 8 2 5 6
8 4 7 1 3 2 9 6 5
4
5
1 4 5 2 3
3 4 2 1 5
3
3
1 2 3
2 3 1
2
2
1 2
1 2
1
2
1 2
2 1
2
3
1 2 3
2 1 3
2
3
1 2 3
1 3 2
2
3
1 2 3
3 2 1
3
3
1 2 3
1 2 3
1
1
1
1
1
5
1 2 5 3 4
3 5 4 2 1
4
5
5 3 2 4 1
2 4 5 1 3
2
5
1 2 4 5 3
1 2 5 4 3
2
5
1 2 3 4 5
1 2 3 4 5
1
5
5 4 3 2 1
1 2 3 4 5
5
5
1 3 5 4 2
1 4 5 3 2
3
5
1 5 2 4 3
4 3 2 5 1
4
25
21 19 25 9 24 23 20 18 16 22 17 7 4 15 13 11 2 3 10 12 14 6 8 5 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
13
30
30 29 28 27 26 25 19 24 9 23 21 20 18 16 22 17 7 4 15 13 11 2 3 10 12 14 6 8 5 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
19
40
40 27 29 39 30 34 28 26 25 38 19 32 24 9 37 23 21 20 18 33 36 16 22 35 17 7 4 15 31 13 11 2 3 10 12 14 6 8 5 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
19
45
45 44 40 43 27 29 41 39 30 34 28 26 25 42 38 19 32 24 9 37 23 21 20 18 33 36 16 22 35 17 7 4 15 31 13 11 2 3 10 12 14 6 8 5 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
22
1
1
1
1
import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
import math 
from types import GeneratorType
#from functools import cache  3.9
mod = 998244353
inf = int(1e20)
input = lambda: sys.stdin.readline().rstrip("\r\n")
MI = lambda :map(int,input().split())
li = lambda :list(MI())
ii = lambda :int(input())
py = lambda :print("YES")
pn = lambda :print("NO")

from bisect import bisect_left

class BIT1:
    """单点修改,区间和查询"""

    __slots__ = "size", "bit", "tree"

    def __init__(self, n: int):
        self.size = n
        self.tree = [0]*(n+1)

    def add(self, index: int, delta: int) -> None:
        # index 必须大于0
        while index <= self.size:
            self.tree[index]+=delta
            index += index & -index

    def _query(self, index: int) -> int: 
        res = 0
        while index > 0:
            res += self.tree[index]
            index -= index & -index
        return res

    def query(self, left: int, right: int) -> int:
        return self._query(right) - self._query(left - 1)


class BIT:
    def __init__(self, n):
        self.n = n
        self.max_tree = [0] * (n + 1)

    def update(self, idx, val):
        while idx <= self.n:
            self.max_tree[idx] = max(self.max_tree[idx], val)
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res = max(res, self.max_tree[idx])
            idx -= idx & (-idx)
        return res

n=ii()

st=[0]*(n+1)
ed=[0]*(n+1)

for i,a in enumerate(li()):
    st[a]=i

for i,a in enumerate(li(),1):
    ed[a]=i

arr=[]

for i in range(1,n+1):
    arr.append([st[i],ed[i]])

arr.sort(key=lambda x:-x[0])


def lengthOfLIS(nums):#二分求lis
    ng = 0  # g 的长度
    for x in nums:
        j = bisect_left(nums, x, 0, ng)
        nums[j] = x
        if j == ng:  # >=x 的 g[j] 不存在
            ng += 1 
    return ng

print(lengthOfLIS([j for i,j in arr]))
