#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int xd[200007];

int main()
{
    magiczne linijki;
    int n, res = 0, diff = 1;
    cin >> n;
    for (int i = n;i>0;i--)
    	cin >> xd[i];
    for (int i = 2*n;i>n;i--)
    	cin >> xd[i];
//    for (int i = 1;i<=2*n;i++)
//    	cout << xd[i] << ' ';
	int i = 1, j = n + 1;
	while (i < n)
	{
		while (xd[i] != xd[j])
			i++;
		res += i - diff;
		diff = i + 1;
		i++;
		j++;
	}
	cout << res;
    return 0;
}


#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int xd[200007];
bool was[100007];

int main()
{
    magiczne linijki;
    int n, res = 0, diff = 1;
    cin >> n;
    for (int i = n;i>0;i--)
    	cin >> xd[i];
    for (int i = 2*n;i>n;i--)
    	cin >> xd[i];
//    for (int i = 1;i<=2*n;i++)
//    	cout << xd[i] << ' ';
	int i = 1, j = n + 1;
	while (i <= n)
	{
		while (xd[i] != xd[j])
		{
			was[xd[i]] = true;
			i++;
		}
		if (i == j)
			break;
		res += i - diff;
		diff = i + 1;
		was[xd[i]] = true;
		i++;
		while (was[xd[j]])
			j++;
	}
	cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n; int a[n+1],b[n+1];
	a[0]=-1; b[0]=-1;
	bool vis[n+1];
	fill( vis,vis+n+1,0);

	for( int i=1;i<=n;i++) cin>>a[i];
	for( int i=1;i<=n;i++) cin>>b[i];

	int i=1;   ////pointer for entering cars for in array
	int j=1;  //pointer for exiting cars for /out array
	int cnt=0;

	for( ; i<=n&& j<=n+1; )
	{

	   if(a[i]==b[j] && !vis[a[i]] && !vis[b[j]] )
	   {
	   	  vis[ b[j] ]= true;
	   	  i++; j++;
	   	  continue ;

	   }
	   if( a[i]!= b[j] && !vis[ a[i] ] && !vis[b[j]])
	   {
	   	cnt++;
		vis[ b[j] ] =true ;
	   	j++;

	   }

	   i++; j++;

	}

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n; int a[n+1],b[n+1];
	a[0]=-1; b[0]=-1;
	bool vis[n+1];
	fill( vis,vis+n+1,0);

	for( int i=1;i<=n;i++) cin>>a[i];
	for( int i=1;i<=n;i++) cin>>b[i];

	int i=1;   ////pointer for entering cars for in array
	int j=1;  //pointer for exiting cars for /out array
	int cnt=0;

	for( ; i<n&& j<n; )
	{

	   if(a[i]==b[i] && !vis[a[i]] && !vis[b[j]] )
	   {
	   	  vis[ b[i] ]= true;
	   	  i++; j++;
	   	  continue ;

	   }
	   if( a[i]!= b[j] && !vis[ a[i] ] && !vis[b[j]])
	   {
	   	cnt++;
		vis[ b[j] ] =true ;
	   	j++;

	   }

	   i++; j++;

	}

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n; int a[n+1],b[n+1];

	bool vis[n+1];

	fill( vis,vis+n+1,0);

	for( int i=1;i<=n;i++) cin>>a[i];
	for( int i=1;i<=n;i++) cin>>b[i];

	int i=1;   //pointer for entering cars for in array
	int j=1;  //pointer for exiting cars for /out array
	int cnt=0;

	/*
	//we will move counter i if
	1.a[i] is previously exited or visited
	2.a[i]==b[i]

	//we will move counter j if
	1.if b[j] is previously exited or visited
	2.a[i]==b[i] or a[i]!= b[i];

	*/

	for( ; i<=n&& j<=n; )
	{

	  if( vis[ a[i] ]) i++;
	  if( vis[ b[j] ]) j++;

	  if( a[i]==b[j])
	  {
	    vis[ b[j] ]=1;
	  	i++; j++;
	  }

	  else
	  {
	  	cnt++;
	  	vis[ b[j] ]=1;
	  	j++;
	  }

	}

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int ar[100006];
long long psum[100006];

int main()
{
     unordered_map<int,int> in,out ;

   int n; cin>>n; int x,cnt=0;

   int a[n+1];
   fill(a,a+n+1,0);

   for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  a[i]=x;
   	  in[x]= i;
   }

     for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  out[x]= i;
   }

   int j=n;

   while( in.size()>0 && j>0 )
   {
      int val= a[j];
      if( in[ val ] != out[val] ) cnt++;

	  in.erase( val )  ;
	  int tmp= out[val];
   	  out.erase( val ) ;
   	  for( auto &c: out)
   	  if(c.second>tmp )c.second--;
   	  j--;
   }

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt = 0;
    cin >> n;

    int a[n], b[n];

	bool vis[n+1];
	fill(vis,vis+n+1,false) ;

    for(int i = 0; i < n; i++)
 	cin >> a[i];

    for(int i = 0; i < n; i++)
    cin >> b[i];

   /*

	//we will move counter i if
	1. visited a[i]!=b[j]
	   A-->if a[i] is previously exited or visited move only i
	   b-->if  a[i] is not  previously exited or visited move  i and j both and increase counter ..mark b[j] vsisited

	2.a[i]==b[j]  move both counter.....mark b[j] vsisited

	*/

    for(int i = 0, j = 0; i < n && j < n; )
    {

	    if(a[i] != b[j])
        {
            if(vis[a[i]])
            {
                i++;
                continue;
            }
            cnt++;
            vis[b[j]] = true;
            j++;
        }
        else
        {
            vis[b[j]] = true;
            i++;
            j++;
        }
    }
    cout << cnt << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n; int a[n+1],b[n+1];
	a[0]=-1; b[0]=-1;
	bool vis[n+1];
	fill( vis,vis+n+1,0);

	for( int i=1;i<=n;i++) cin>>a[i];
	for( int i=1;i<=n;i++) cin>>b[i];

	int i=1;   ////pointer for entering cars for in array
	int j=1;  //pointer for exiting cars for /out array
	int cnt=0;

	for( ; i<=n&& j<=n; )
	{

	   if(a[i]==b[j] && !vis[a[i]] && !vis[b[j]] )
	   {
	   	  vis[ b[j] ]= true;
	   	  i++; j++;
	   	  continue ;

	   }
	   if( a[i]!= b[j] && !vis[ a[i] ] && !vis[b[j]])
	   {
	   	cnt++;
		vis[ b[j] ] =true ;
	   	j++;

	   }

	   i++; j++;

	}

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int ar[100006];
long long psum[100006];

int main()
{
     map<int,int> in,out ;
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int n; cin>>n; int x,cnt=0;

   int a[n+1];
   fill(a,a+n+1,0);

   for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  a[i]=x;
   	  in[x]= i;
   }

     for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  out[x]= i;
   }

   int j=n;

   while( in.size()>0 && j>0 )
   {
      int val= a[j];
      if( in[ val ] != out[val] ) cnt++;

	  in.erase( val )  ;
	  int tmp= out[val];
   	  out.erase( val ) ;
   	  for( auto &c: out)
   	  if(c.second>tmp )c.second--;
   	  j--;
   }

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int ar[100006];
long long psum[100006];

int main()
{
     map<int,int> in,out ;

   int n; cin>>n; int x,cnt=0;

   int a[n+1];
   fill(a,a+n+1,0);

   for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  a[i]=x;
   	  in[x]= i;
   }

     for(int i=1;i<=n;i++)
   {
   	  cin>>x;
   	  out[x]= i;
   }

   int j=n;

   while( in.size()>0 && j>0 )
   {
      int val= a[j];
      if( in[ val ] != out[val] ) cnt++;

	  in.erase( val )  ;
	  int tmp= out[val];
   	  out.erase( val ) ;
   	  for( auto &c: out)
   	  if(c.second>tmp )c.second--;
   	  j--;
   }

	cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt = 0;
    cin >> n;

    int a[n], b[n];

	bool vis[n+1];
	fill(vis,vis+n+1,false) ;

    for(int i = 0; i < n; i++)
 	cin >> a[i];

    for(int i = 0; i < n; i++)
    cin >> b[i];

   /*

    case:

	1. visited a[i]!=b[j]
	   A-->if a[i] is previously exited or visited move only i
	   b-->if  a[i] is not  previously exited or visited move  i and j both and increase counter ..mark b[j] vsisited

	2.a[i]==b[j]  move both counter.....mark b[j] vsisited

	*/

    for(int i = 0, j = 0; i < n && j < n; )
    {

	    if(a[i] != b[j])
        {
            if(vis[a[i]])
            {
                i++;
                continue;
            }
            cnt++;
            vis[b[j]] = true;
            j++;
        }
        else
        {
            vis[b[j]] = true;
            i++;
            j++;
        }
    }
    cout << cnt << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n; int a[n+1],b[n+1];
	a[0]=-1; b[0]=-1;
	bool vis[n+1];
	fill( vis,vis+n+1,0);

	for( int i=1;i<=n;i++) cin>>a[i];
	for( int i=1;i<=n;i++) cin>>b[i];

	int i=1;   ////pointer for entering cars for in array
	int j=1;  //pointer for exiting cars for /out array
	int cnt=0;

	for( ; i<n&& j<n; )
	{

	   if(a[i]==b[j] && !vis[a[i]] && !vis[b[j]] )
	   {
	   	  vis[ b[j] ]= true;
	   	  i++; j++;
	   	  continue ;

	   }
	   if( a[i]!= b[j] && !vis[ a[i] ] && !vis[b[j]])
	   {
	   	cnt++;
		vis[ b[j] ] =true ;
	   	j++;

	   }

	   i++; j++;

	}

	cout<<cnt<<endl;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, k;
  cin >> n;
  ll a[n], b[n];
  for (auto i = 0; i < n; i++) cin >> a[i];
  for (auto i = 0; i < n; i++) cin >> b[i];
  bool f[n];
  ll ans = 0;
  memset(f, false, sizeof f);
  ll i = 0, j = 0;
  while (i < n and j < n) {
    if (f[a[i]] == true) {
      i++;
    } else if (a[i] == b[j]) {
      i++;
      j++;
    } else {
      f[b[j]] = true;
      j++;
      ans++;
    }
  }
  std::cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    --b[i];
  }
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    pos[b[i]] = i;
  }
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = pos[a[i]];
  }
  int mx = -1, ans = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] > mx) {
      mx = c[i];
    } else {
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n;

  int a[n], j = 0, ans = 0, b;
  for (int i = 0; i < n; i++) cin >> a[i];

  bool f[n];
  memset(f, false, sizeof(f));
  for (int i = 0; i < n; i++) {
    cin >> b;
    while (f[a[j]] and j < n-1) j++;
    if (a[j] == b)
      j++;
    else {
      f[b] = true;
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, k;
  cin >> n;
  ll a[n], b[n];
  for (auto i = 0; i < n; i++) cin >> a[i];
  for (auto i = 0; i < n; i++) cin >> b[i];
  bool f[n];
  ll ans = 0;
  memset(f, false, sizeof f);
  ll i = 0, j = 0;
  while (i < n and j < n) {
    if (f[i] == true) {
      i++;
    } else if (a[i] == b[j]) {
      i++;
      j++;
    } else {
      f[b[j]] = true;
      j++;
      ans++;
    }
  }
  cout << ans << "\n";

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  bool f[n];
  memset(f, false, sizeof f);
  for (register int i = 0; i < n; i++) cin >> a[i];

  int ans = 0, j = 0, b;
  for (register int i = 0; i < n; i++) {
    cin >> b;
    while (f[a[j]] and j < n) j++;
    if (a[j] == b)
      j++;
    else {
      f[b] = true;
      ans++;
    }
  }
  return cout << ans << "\n", 0;
}


#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, k;
  cin >> n;
  ll a[n], b[n];
  for (auto i = 0; i < n; i++) cin >> a[i];
  for (auto i = 0; i < n; i++) cin >> b[i];
  bool f[n];
  ll ans = 0;
  memset(f, false, sizeof f);
  ll i = 0, j = 0;
  while (i < n and j < n) {
    if (f[i] == true) {
      i++;
    } else if (a[i] == b[j]) {
      i++;
      j++;
    } else {
      if (f[j] == false) {
        f[j] = true;
        ans++;
      }
      j++;
    }
  }
  cout << ans << "\n";

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, k;
  cin >> n;
  ll a[n], b[n];
  for (auto i = 0; i < n; i++) cin >> a[i];
  for (auto i = 0; i < n; i++) cin >> b[i];
  bool f[n];
  ll ans = 0;
  memset(f, false, sizeof f);
  ll i = 0, j = 0;
  while (i < n or j < n) {
    if (f[i] == true) {
      i++;
    } else if (a[i] == b[j]) {
      i++;
      j++;
    } else {
      j++;
      f[j] = true;
      ans++;
    }
  }
  cout << ans << "\n";

#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }

        vin(b,n);
        fo(0,n) {
            if(!ok[a[i]-1]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]-1]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }

        vin(b,n);
        j=0;
        fo(0,n) {
            if(!ok[a[i]]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) {
                        j++;
                        break;
                    }
                    else {
                        cc++;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }
j=0;
        vin(b,n);
        fo(0,n) {
            if(!ok[a[i]-1]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=j; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]-1]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }

        vin(b,n);
        j=0;
        fo(0,n) {
            if(!ok[a[i]]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) {
                        j++;
                        break;
                    }
                    else {
                        cc++;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }
        vin(b,n);
        fo(0,n) {
            if(ok[a[i]]==false) continue;
            // else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    if(!ok(b[j])) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }
        vin(b,n);
        fo(0,n) {
            if(ok[a[i]]==false) continue;
            // else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }

        vin(b,n);
        j=0;
        fo(0,n) {
            if(!ok[a[i]]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=j; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) {
                        j++;
                        break;
                    }
                    else {
                        cc++;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }

        vin(b,n);
        fo(0,n) {
            if(!ok[a[i]-1]) continue;
            else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]-1]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(1);
        }

        vin(b,n);
        j=0;
        fo(0,n) {
            if(!ok[a[i]-1]) continue;
            //else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                // co<<x<<vd<<i;NL;
                for(; j<n; j++) {
                    //if(!ok(b[j])) continue;
                    if(x==b[j]) {
                        // co<<"got"<<j<<vd<<b[j]<<vd<<cc<<nl;
                        j++;
                        break;
                    }
                    else {
                        cc++;
                        ok[b[j]-1]=0;
                        //co<<j<<vd<<b[j]<<vd<<cc<<nl;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>
#include<functional>
#include<numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define nl "\n"
#define NL co<<nl
#define vd " "
#define F first
#define S second
#define fo(a,b) for(i=a;i<b;i++)
#define Fo(a,b) for(i=a;i>=b;i--)
#define fo1(a,b) for(j=a;j<b;j++)
#define Fo1(a,b) for(j=a;j>=b;j--)
#define fo2(a,b,c) for(i=a;i<=b;i+=c)
#define Fo2(a,b,c) for(i=a;i<=b;i-=c)
#define pb push_back
#define mp make_pair
#define popf pop_front
#define popb pop_back
#define eb emplace_back
#define ins insert
#define sf scanf
#define pf printf
#define all(v)  v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define tc(T) while(T--)
#define vec vector
#define co cout
#define d(x) co<<to_string(x)<<vd<<x<<vd
#define yes co<<"YES\n"
#define no co<<"NO\n"
#define yes2 co<<"Yes\n"
#define no2 co<<"No\n"
#define stol(s) stoll(s,nullptr,10)
#define vl vec<ll>
#define usl unordered_set<ll>
#define ml map<ll,ll>
#define mllit map<ll,ll>::iterator
#define mplll map<pair<ll,ll>,ll>
#define msl map<string,ll>
#define vpl vec<pair<ll,ll>>
#define sl set<ll>
#define mlb map<ll,bool>
#define vb vec<bool>
#define spll set<pair<ll,ll>>
#define spsl set<pair<string,ll>>
#define slit set<ll>::iterator
#define spllit set<pair<ll,ll>>::iterator
#define in(a,n) fo(0,n){cin>>a[i];}
#define vin(a,n) fo(0,n){cin>>q;a.eb(q);}
#define vsinin(a) {cin>>q;a.pb(q);}
#define vpin(a,n) fo(0,n){cin>>q>>w;a.pb({q,w});}
#define vpout(b,n) fo(0,n){co<<b[i].F<<vd<<b[i].S<<nl;}
#define out(a,n) fo(0,n){cout<<a[i]<<vd;}
#define in2d(a,n,m) fo(0,n){for(j=0;j<m;j++){cin>>a[i][j];}}
#define out2d(a,n,m) fo(0,n){for(j=0;j<m;j++){co<<a[i][j]<<vd;} co<<nl;}
#define factors(a,n) if(n==1){a.pb(1);} else{fo(1,sqrt(n)+1){if(n%i==0){a.pb(i);if(i!=n/i){a.pb(n/i);}}}sort(all(a));}
#define MX(a) *max_element(a,a+n)
#define MN(a) *min_element(a,a+n)
#define VMX(a) *max_element(all(a))
#define VMN(a) *min_element(all(a))
#define lowb(a,x) (std::lower_bound(a.begin(),a.end(),x)-a.begin())
#define upb(a,x) (std::upper_bound(a.begin(),a.end(),x)-a.begin())
#define beg begin()
#define rbeg rbegin()
#define ren rend()
#define en end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
ll T=1,inf=100000000000000000,mod=1000000007;
ll ncr(ll n,ll r)
{
    ll l=n,f2=1,l2=n-r,i=1,j=1;
    if (r != 0||r!=n)
    {
        while (l2!=0||l!=r)
        {
            i*= l;
            j*= l2;
            ll m = gcd(i,j);
            i/= m;
            j/= m;
            l--;
            l2--;
        }
    }
    else i = 1;
    return i;
}
ll dig_sum(ll n) {
    ll v=n,sum=0,i;
    while(v) {
        sum+=v%10;
        v/=10;
    }
    return sum;

}
bool ckprime(ll n) {
    if(n%2==0&&n!=2) return 0;
    else if(n==2) return 1;
    else {
        ll v=sqrt(n),flag=1,i;
        for(i=3; i<=v; i+=2) {
            if(n%i==0) {
                flag=0;
                break;
            }
        }
        return flag;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //cin >> T;
    while(T--)
    {
        ll n,sz=1,ans=0,blag=0,u,mn=0,ev=0,mx=0,mini,i,v,q,p,j,k,w,h,l,m,x,y,od=0,total=0,cc=0,pp=0,flag=0,klag=0,sum=0;
        string s,s1,s2;
        //bool ok=1;
        cin>>n;
        vl a,b;
        vb ok;
        ml cnt,ent;
        fo(0,n) {
            cin>>q;
            a.pb(q);
            ok.pb(true);
        }
        vin(b,n);
        fo(0,n) {
            if(ok[a[i]]==false) continue;
            // else if(a[i]==b[i]) continue;
            else {
                x=a[i];
                for(j=i; j<n; j++) {
                    if(!ok[b[j]]) continue;
                    if(x==b[j]) break;
                    else {
                        cc++;
                        i=j;
                        ok[b[j]]=false;
                    }
                }
            }

        }

        co<<cc<<nl;

    }
    return 0;
}
/*If I get WA-
check special cases for 0,1,2...
if it seems in 1200-check special cases or bugs.
if seems 1300/1400/1500 -missed any cases.
-if get wa again and again after adding case-Change logic.
*/


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		r += ar[i];
		if(i < rec[x] + r){
			ar[rec[x] + r] -= 1;
			r++;
			cnt++;
		}
	}
	cout<<cnt el;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		bool fl = 1;
		if(i < rec[x] + r){
			fl = 0;
			r += ar[i];
			if(rec[x] + r < n ) ar[rec[x] + r] -= 1;
			r++;
			cnt++;
		}
		if(fl) r += ar[i];
	}
	cout<<cnt el;
	//for(int e: ar) cout<<e sp;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); int n; cin>>n;
	map<int,int> in;
	int cnt = 0, out[n];
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		in[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		out[in[x]] = i;
	}
	int mx = out[0];
	for(int i = 1; i < n; i++){
		if(mx > out[i]){
			cnt++;
		}
		mx = max(mx,out[i]);
	}
	cout<<cnt el;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		if(i < rec[x] + r){
			if(rec[x] + r < n )ar[rec[x] + r] -= 1;
			r++;
			cnt++;
		}
		r += ar[i];
	}
	cout<<cnt el;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		bool fl = 1;
		if(i < rec[x] + r){
			fl = 0;
			r += ar[i];
			if(rec[x] + r < n ) ar[rec[x] + r] -= 1;
			r++;
			cnt++;
		}
		if(fl) r += ar[i];
	}
	cout<<cnt el;
	for(int e: ar) cout<<e sp;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		if(i < rec[x] + r){
			ar[rec[x] + r] -= 1;
			r++;
			cnt++;
		}
		r += ar[i];
	}
	cout<<cnt el;
	return 0;
}


#include "iostream"
#include "algorithm"
#include "iomanip"
#include "vector"
#include "set"
#include "sstream"
#include "fstream"
#include "cstring"
#include "cmath"
#include "utility"
#include "map"
#include "bitset"
#include "cassert"
#include "deque"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin>>n;
	int r = 0,cnt = 0, ar[n];
	map<int,int> rec;
	memset(ar,0,sizeof(ar));
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		rec[x] = i;
	}
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		r += ar[i];
		if(i < rec[x] + r){
			ar[rec[x]] -= 1;
			r++;
			cnt++;
		}
	}
	cout<<cnt el;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
      s.insert(a[i]);
      i--;
    }
  }
  cout << s.size()*4 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
      s.insert(a[i]);
      i--;
    }
  }
  cout << 3 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
      s.insert(a[i]);
      i--;
    }
  }
  cout << s.size();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
    //   s.insert(a[i]);
      i--;
    }
  }
  cout << s.size() << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
      s.insert(a[i]);
      i--;
    }
  }
  cout << s.size()+5 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  set<int> s;
  int i = n - 1, j = n - 1;
  while (i >= 0 and j >= 0) {
    if (s.count(b[j]) > 0) {
      j--;
    } else if (a[i] == b[j]) {
      i--, j--;
    } else {
      s.insert(a[i]);
      i--;
    }
  }
  cout << s.size()-4 << endl;
  return 0;
}


#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
const int maxm=1e5+5;
int a[maxm];
int b[maxm];
int mark[maxm];
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mark[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        b[i]=mark[b[i]];
    }
//    for(int i=1;i<=n;i++){
//        cout<<b[i]<<' ';
//    }
//    cout<<endl;
    int ans=0;
    int cnt=1;
    memset(mark,0,sizeof mark);
    for(int i=1;i<=n;i++){
        if(mark[cnt])continue;
        if(b[i]!=cnt){
            mark[b[i]]++;
            ans++;
        }else{
            cnt++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*
 *                             UM.
 *                            J@B@1                                                                    iO@1
 *                           Y@@@B@BB.                                                              7B@B@B@
 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
 *               ZB@B.                                              ,v.                                        @B@L
 *              LB@B,                         Y7                    @B@Bu                                      7@B@
 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
 *           2@B@                                                                                ,O@B@B@B@B
 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
 *           @B@                         @B@B@@@i                       rL7.                                    B@BM
 *           B@B7.:                       NB@@M.                                                               .@B@.
 *  .;JEB@@@B@B@B@B@.                                                                                .  @B@u
 *@@@B@B@B@B@@@B@18U                                                                                :B@B@B@BU,
 *7@BOui.    ,@@B                                                                                SP@B@B@B@B@Or
 *            @@@U                                                                                B@BJ.YO@B@B@i
 *            r@B@                                                                                :B@Bk     .k@B@
 *             B@B@                                                                                LB@@k         2i
 *              B@BM                                      .7jXEGqF7:                                     OB@@L
 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G
 *                 B@@@S                                                                           ,MB@B@,
 *                  v@@@BF                                                                      .1B@B@Br
 *                    2@@B@BL                                                                ,FB@@@B8,
 *                      r@B@B@BF,                                                        :YBB@B@B@B
 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2
 *                          i@@@@                     0@B@u          B@@B.                       vB@B
 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
 *                          vNi                          S@@B@B@B@B@BM:                            MB@N
 *                                                          758BMqJ,
 *
 *                 .  YO.               vq                            :G       Z:
 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
 *                          .ll                                           rB.                     :
 */


#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<set>
using namespace std;
const int maxm=1e5+5;
int a[maxm];
int b[maxm];
int mark[maxm];
int n;
struct Node{
    int in,out;
}e[maxm];
bool cmp(Node a,Node b){
    return a.in<b.in;
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        e[a[i]].in=i;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        e[b[i]].out=i;
    }
    sort(e+1,e+1+n,cmp);
    int ans=0;
    int ma=0;
    for(int i=1;i<=n;i++){
        ma=max(ma,e[i].out);
        if(ma>e[i].out)ans++;
    }
    cout<<ans<<endl;
    return 0;
}
/*
 *                             UM.
 *                            J@B@1                                                                    iO@1
 *                           Y@@@B@BB.                                                              7B@B@B@
 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
 *               ZB@B.                                              ,v.                                        @B@L
 *              LB@B,                         Y7                    @B@Bu                                      7@B@
 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
 *           2@B@                                                                                ,O@B@B@B@B
 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
 *           @B@                         @B@B@@@i                       rL7.                                    B@BM
 *           B@B7.:                       NB@@M.                                                               .@B@.
 *  .;JEB@@@B@B@B@B@.                                                                                .  @B@u
 *@@@B@B@B@B@@@B@18U                                                                                :B@B@B@BU,
 *7@BOui.    ,@@B                                                                                SP@B@B@B@B@Or
 *            @@@U                                                                                B@BJ.YO@B@B@i
 *            r@B@                                                                                :B@Bk     .k@B@
 *             B@B@                                                                                LB@@k         2i
 *              B@BM                                      .7jXEGqF7:                                     OB@@L
 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G
 *                 B@@@S                                                                           ,MB@B@,
 *                  v@@@BF                                                                      .1B@B@Br
 *                    2@@B@BL                                                                ,FB@@@B8,
 *                      r@B@B@BF,                                                        :YBB@B@B@B
 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2
 *                          i@@@@                     0@B@u          B@@B.                       vB@B
 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
 *                          vNi                          S@@B@B@B@B@BM:                            MB@N
 *                                                          758BMqJ,
 *
 *                 .  YO.               vq                            :G       Z:
 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
 *                          .ll                                           rB.                     :
 */


#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<set>
using namespace std;
const int maxm=1e5+5;
int in[maxm];
int out[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>in[i];
    }
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        out[x]=i;
    }
    int ans=0;
    int ma=0;
    for(int i=1;i<=n;i++){
        ma=max(ma,out[in[i]]);
        if(ma>out[in[i]]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*
 *                             UM.
 *                            J@B@1                                                                    iO@1
 *                           Y@@@B@BB.                                                              7B@B@B@
 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
 *               ZB@B.                                              ,v.                                        @B@L
 *              LB@B,                         Y7                    @B@Bu                                      7@B@
 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
 *           2@B@                                                                                ,O@B@B@B@B
 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
 *           @B@                         @B@B@@@i                       rL7.                                    B@BM
 *           B@B7.:                       NB@@M.                                                               .@B@.
 *  .;JEB@@@B@B@B@B@.                                                                                .  @B@u
 *@@@B@B@B@B@@@B@18U                                                                                :B@B@B@BU,
 *7@BOui.    ,@@B                                                                                SP@B@B@B@B@Or
 *            @@@U                                                                                B@BJ.YO@B@B@i
 *            r@B@                                                                                :B@Bk     .k@B@
 *             B@B@                                                                                LB@@k         2i
 *              B@BM                                      .7jXEGqF7:                                     OB@@L
 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G
 *                 B@@@S                                                                           ,MB@B@,
 *                  v@@@BF                                                                      .1B@B@Br
 *                    2@@B@BL                                                                ,FB@@@B8,
 *                      r@B@B@BF,                                                        :YBB@B@B@B
 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2
 *                          i@@@@                     0@B@u          B@@B.                       vB@B
 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
 *                          vNi                          S@@B@B@B@B@BM:                            MB@N
 *                                                          758BMqJ,
 *
 *                 .  YO.               vq                            :G       Z:
 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
 *                          .ll                                           rB.                     :
 */