#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXS = 20000 + 10;
const int MAXN = 1000 + 10;
const int INF  = 1e9;

int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        pos[b[i]] = i;
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        a[i] = pos[a[i]];
    }

    int last = a[1], ans = 1;
    for (int i = 2 ; i <= n ; ++i)
    {
        if (a[i] != last + 1)
        {
            ans++;
            last = a[i];
        } else last++;
    }

    std::cout << ans << '\n';
}

void read()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> b[i];
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
