#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
const int MAX = 1e5 + 5;
int n, i;
// 1-index queries
struct fenwick{
int BIT[MAX];
void upd(int i, int val)
{
for(; i <= n; i += i&-i)
BIT[i] = max(BIT[i], val);
}
int qry(int i)
{
int mx = 0;
for(; i; i -= i&-i)
mx = max(mx, BIT[i]);
return mx;
}
} ft;
int main()
{
boost;
cin >> n;
int a[n], b[n];
fo(i, 0, n)
cin >> a[i];
fo(i, 0, n)
cin >> b[i];
map <int, int> mp;
fo(i, 0, n)
mp[a[i]] = i;
int mx = 0;
fo(i, 0, n) {
if(mp.find(b[i]) != mp.end()) {
int val = ft.qry(mp[b[i]]) + 1;
ft.upd(mp[b[i]] + 1, val);
mx = max(mx, val);
}
}
cout << mx;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nIGludAojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHMgc2Vjb25kCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgZWIgZW1wbGFjZV9iYWNrCiNkZWZpbmUgbWsgbWFrZV9wYWlyCiNkZWZpbmUgbXQgbWFrZV90dXBsZQojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgZm8oaSxhLGIpIGZvcihpPWE7aTxiO2krKykKI2RlZmluZSBmb2UoaSxhLGIpI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