object Main{
  def main(args: Array[String]){
    val sc=new java.util.Scanner(System.in)
    val n=sc.nextInt()
    val v=mysprit(n,sc)
    val std=v.map(x=>(List(0,0)::mysort(x,Nil)).sortBy(-_(1)).take(2)).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 match{
      case Nil => r
      case x::xs => mysort(
        xs filter (_!=x),
        (x :: 1+xs.count(_==x) :: Nil) :: r
      )
    }
  }
  def mysprit(n:Int,s:java.util.Scanner):List[List[Int]] = {
    def myspritlocal(c:Int,l1:List[Int],l2: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)
  }
}