pls AC T_T
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
#define pii pair<long long, long long>
#define endl "\n"
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define FILE(A) freopen(A".INP", "r", stdin); freopen(A".OUT", "w", stdout)
using namespace std;
const int N = 2e5+5;
const int oo = 1e16 ;
const int MOD = 1e9+7;
const int BASE = 31 ;
int n,a[N], b[N];
bool mark[N];
void sub1() {
memset(mark, false, sizeof mark);
int ans = 0;
for (int i=1;i <= n;i++) {
int num = b[i], Top;
for (int j=1;j <= n;j++) {
if (mark[a[j]]) continue;
Top = a[j];
break;
}
if (num != Top)
ans++;
mark[num] = true;
}
cout << ans;
}
void sub2() {
memset(mark, false, sizeof mark);
int ans = 0;
int j=1;
for (int i=1;i <= n;i++) {
int num = b[i];
while(mark[a[j]]) {
j++;
}
if (num != a[j])
ans++;
mark[num] = true;
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
FILE("ANTS");
cin >> n;
for (int i=1;i <= n;i++)
cin >> a[i];
for (int i=1;i <= n;i++)
cin >> b[i];
// sub1();
sub2();
cerr << "Time elapsed: " << TIME << "s.\n";
return 0;
}
// Nguyen Minh Hieu - 2008 - Gia Lai.
// https://hieuhfgr.pythonanywhere.com/