program two_contests
  implicit none
  integer :: n, a(0:100001,2) = 0, pre(0:100001) = 0, suf(0:100001) = 0, i, x = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i,1:2)
  end do
  call merge_sort(a(1:n,1:2))
  pre(0) = 1e9
  suf(n+1) = 1e9
  do i = 1, n
    pre(i) = min(pre(i-1),a(i,2))
  end do
  do i = n, 1, -1
    suf(i) = min(suf(i+1),a(i,2))
  end do
  do i = 1, n-1
    x = max(x,max(calc(a(i,1),pre(i))+calc(a(n,1),suf(i+1)),calc(a(i,1),a(i,2))+calc(a(n,1),min(pre(i-1),suf(i+1)))))
  end do
  write(*,'(i0)') x
contains
  integer function calc(l,r)
    integer, intent(in) :: l, r
    calc = r-l+1
    if (l > r) calc = 0
  end
  subroutine merge_sort(a)
    integer, intent(inout) :: a(:,:)
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(a1,a2)
    integer, intent(inout) :: a1(:,:), a2(:,:)
    integer :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1,1)
    n2 = size(a2,1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (a1(i1,1) < a2(i2,1) .or. &
      & (a1(i1,1) == a2(i2,1) .and. a1(i1,2) <= a2(i2,2))) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
  end
end program two_contests