    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef pair<int,int> pi;
    #define PB push_back
    #define MP make_pair
    #define REP(i,a,b) for(int i = a; i<=b; i++)
void print(stack<char> st){
    while(!st.empty()){
        cout << st.top() << " ";
        st.pop();
    }
}
    int main (){
    	ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n = 0;
        cin >> n;
        int a[n], b[n];
        int maxa = INT_MIN , minb = INT_MAX;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            maxa = max(maxa, a[i]);
        }
        for(int i = 0; i < n; i++){
            cin >> b[i];
            minb = min(minb, b[i]);
        }
        int ans = minb - maxa + 1;
        if(ans <= 0){
            cout << 0 << "\n";
        }else{
            cout << ans  << "\n";
        }
        return 0;
    }

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define loops(i, s, n) for (ll i = s; i < (ll)n; i++)
#define loop(i, n) loops(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define pub push_back
#define pob pop_back
#define mp make_pair
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> v;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vl;

inline int in_int()
{
  int x;
  cin >> x;
  return x;
}
inline ll in_ll()
{
  ll x;
  cin >> x;
  return x;
}
inline string in_str()
{
  string x;
  cin >> x;
  return x;
}

// for dp
// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T>
inline bool chmin(T &a, const T &b)
{
  bool compare = a > b;
  if (a > b)
    a = b;
  return compare;
}
template <typename T>
inline bool chmax(T &a, const T &b)
{
  bool compare = a < b;
  if (a < b)
    a = b;
  return compare;
}
void _INPUT_IMPL_(){};
template <class T, class... Args>
void _INPUT_IMPL_(T &dest, Args &...args)
{
  cin >> dest;
  _INPUT_IMPL_(args...);
}
void _OUTPUT_IMPL_(){};
template <class T, class... Args>
void _OUTPUT_IMPL_(T dest, Args... args)
{
  cout << dest << (sizeof...(Args) ? " " : "");
  _OUTPUT_IMPL_(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) \
  vector<type> name(cnt);     \
  loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout << std::endl)
#define set_fix(x) ((std::cerr << std::fixed << std::setprecision(x)), (std::cout << std::fixed << std::setprecision(x)))

//cout for vector
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

// gcd
ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}

//prime numbers
bool IsPrime(ll num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (ll i = 3; i <= sqrtNum; i += (ll)2)
  {
    if (num % i == 0)
    {
      return false;
    }
  }
  return true;
}
vector<ll> Eratosthenes(ll N)
{
  int arr[N];
  vector<ll> res;
  for (int i = 0; i < N; i++)
  {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(N); i++)
  {
    if (arr[i])
    {
      for (int j = 0; i * (j + 2) < N; j++)
      {
        arr[i * (j + 2)] = 0;
      }
    }
  }

  for (int i = 2; i < N; i++)
  {
    if (arr[i])
    {
      res.push_back(i);
    }
  }
  return res;
}

//digit number
int GetDigit(ll num, ll radix)
{
  unsigned digit = 0;
  while (num != 0)
  {
    num /= radix;
    digit++;
  }
  return digit;
}

int digsum(ll n)
{
  ll res = 0;
  while (n > 0)
  {
    res += n % (ll)10;
    n /= (ll)10;
  }
  return res;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  set<int> a;
  for (int i = 0; i < n; i++)
  {
    int ai;
    cin >> ai;
    a.insert(ai);
  }
  int mn = *a.begin();
  int mx = *a.rbegin();
  dump(mx);
  dump(mn);
  int cnt = 0;
  while (mx != mn)
  {
    a.erase(mx);
    a.insert(mx - mn);
    mn = *a.begin();
    mx = *a.rbegin();
    cnt++;
    // cout << "cnt: " << cnt << " mx: " << mx << " mn: " << mn << endl;
  }

  cout << mx << endl;
  return 0;
}
