#include <cstdio>
#include <cassert>
#include <algorithm>

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

using namespace std;

#define m 2100

pair <int, int> a[m];
int n;

int main()
{
  freopen("wires.in", "r", stdin);
  freopen("wires.out", "w", stdout);
  scanf("%d", &n);
  assert(1 <= n && n <= 1000);
  n *= 2;
  forn (i, n)
  {
    scanf("%d", &a[i].first), a[i].second = i / (n / 2);
    assert(0 <= a[i].first && a[i].first <= 100000);
  }
  sort(a, a + n);
  int nu = 0, res = 0;
  forn (i, n)
  {
    if (i)
      res += (long long)nu * (a[i].first - a[i - 1].first);
    assert(i == 0 || a[i].first == a[i - 1].first || nu >= 0);
    if (a[i].second == 0)
      nu++;
    else
      nu--;
  }
  assert(nu == 0);
  printf("%d\n", res);
  return 0;
}
