#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
int M=1000000007;
const int N=200005;

signed main(){
  int t1=1;
  //cin>>t1;
  while(t1--){
    int n;
    cin>>n;

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

    for(int i=1;i<1005;i++) a[i]+=a[i-1];

    int cnt=0;
    for(int i=1;i<=1000;i++) if(a[i]==n) cnt++;
    cout<<cnt<<endl;
  }
}

#include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<set>
#include<array>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const long long INF = 1e18;
using ll = long long;
using P = pair<int,int>;

void chmin(int &x,int y){ x = min(x,y); }

int digit(ll x){
  int count = 1;
  while(x/10>0){
    count ++;
    x /= 10;
  }
  return count;
}

bool prime(ll x){
  if(x==1) return false;
  for(ll i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

void decom(ll x,map<ll,int> &hatano){
  for(ll i=2;i*i<=x;i++){
    if(x%i==0&&prime(i)){
      while(x%i==0){
      x /= i;
      hatano[i] ++;
    }
    }
  }
  if(x!=1) hatano[x] ++;
}

ll speedpow(ll x,ll y){
  ll res = 1;
  ll test = x;
  for(int i=0;i<31;i++){
    if(y&(1<<i)) res *= test;
    res = res%MOD;
    test = (test*test)%MOD;
  }
  return res;
}

ll combination(ll x,ll y){
  ll test = 1;
  ll test1 = 1;
  for(ll i=0;i<y;i++){
    test = (test*(x-i))%MOD;
    test1 = (test1*(i+1LL))%MOD;
  }
  return (test * speedpow(test1,MOD-2))%MOD ;
}

int euclid(int x,int y){
  if(y==0) return x;
  return euclid(y,x%y);
}


/*int main(){
  int n;cin >> n;
  ll m;cin >> m;

  ll a[n];
  rep(i,n) cin >> a[i];

}*/


int main(){
    int n;cin >> n;
    int a[n],b[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    int ans = 0;

    for(int i=1;i<=1000;i++){
      bool kon = true;
      rep(j,n){
        if(a[j]>i||b[j]<i) kon = false;
      }
      if(kon) ans ++;
    }

    cout << ans << endl;

}
