// 問題の URL を書いておく
// 

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = long long;

int main(int, const char**)
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    int ans = 0;
    rep(i, 1000)
    {
        auto t = i + 1;
        bool valid = true;
        rep(j, N)
        {
            if(!(A[j] <= t && t <= B[j]))
            {
                valid = false;
                break;
            }
        }
        if(valid) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n; cin >> n;
  int a = 0, b = 1000000;
  for (int i = 0; i < n; i++) {
    int a1; cin >> a1;
    a = max(a1, a);
  }
  for (int i = 0; i < n; i++) {
    int b1; cin >> b1;
    b = min(b1, b);
  }
  if (b < a) cout << 0;
  else cout << b - a + 1;
}