object Main{
  def main(args: Array[String]){
    val sc=new java.util.Scanner(System.in)
    val n=sc.nextInt()
    val std=mysprit(n,sc).map(x=>(List(0,0)::mysort(x,Nil)).sortBy(l=>l(0)(1)-l(1)(1)))
    std match{
      case List(a:List[List[Int]],b:List[List[Int]]) if a(0)(0)==b(0)(0) => println(n-(a(1)(1)+b(0)(1)))
      case List(a:List[List[Int]],b:List[List[Int]]) => println(n-(a(0)(1)+b(0)(1)))
    }
  }
  def mysort(l:List[Int],r:List[List[Int]]) : List[List[Int]] = {
    l.sorted match{
      case Nil => r
      case x::xs => {
        val n = xs.indexWhere(_!=x)+1
        mysort(xs.drop(n), (x :: n+1 :: Nil) :: r )
      }
    }
  }
  def mysprit(n:Int,s:java.util.Scanner):List[List[Int]] = {
    def myspritlocal(c:Int,l1:List[Int],l2:List[Int]):List[List[Int]] ={
      c match{
        case 0 => List(l1,l2)
        case a:Int => myspritlocal(a-2,s.nextInt()::l1,s.nextInt()::l2)
      }
    }
    myspritlocal(n,Nil,Nil)
  }
}