program interval_game
  implicit none
  integer :: n, l(100001), r(100001), i
  integer(8) :: k
  l = 0
  r = 0
  k = 0_8
  read(*,*) n
  do i = 1, n
    read(*,*) l(i), r(i)
  end do
  call bitonic_sort(l(1:n+1),.false.)
  call bitonic_sort(r(1:n+1),.true.)
  do i = 1, n+1
    k = k+2_8*max(0_8,int(l(i)-r(i),8))
  end do
  write(*,'(i0)') k
  stop
contains
  recursive subroutine bitonic_sort(a,ascend)
    implicit none
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n
    n = size(a)
    if (n.eq.1) return
    call bitonic_sort(a(1:n/2),.not.ascend)
    call bitonic_sort(a(n/2+1:n),ascend)
    call bitonic_merge(a,ascend)
    return
  end subroutine bitonic_sort
  recursive subroutine bitonic_merge(a,ascend)
    implicit none
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n, m, i, b
    n = size(a)
    if (n.eq.1) return
    m = 1
    do while (2*m.lt.n)
      m = 2*m
    end do
    do i = 1, n-m
      if ((a(i).gt.a(i+m)).eqv.ascend) then
        b = a(i)
        a(i) = a(i+m)
        a(i+m) = b
      end if
    end do
    call bitonic_merge(a(1:m),ascend)
    call bitonic_merge(a(m+1:n),ascend)
    return
  end subroutine bitonic_merge
end program interval_game