import java.util.Comparator

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()

    case class Seg(id: Int, l: Int, r: Int) {

      /**
        * @return (距離, 場所)
        */
      def move(p: Int): (Int, Int) = {
        if (l to r contains p) {
          (0, p)
        } else if (abs(p - l) > abs(p - r)) {
          (abs(p - r), r)
        } else {
          (abs(p - l), l)
        }
      }
    }

    def newComp(f: Seg => Int) = new Comparator[Seg] {
      override def compare(o1: Seg, o2: Seg): Int = Integer.compare(f(o1), f(o2))
    }

    val Q = Array.ofDim[Seg](2, N)
    rep(N) { i =>
      val s = Seg(i, ni(), ni())
      rep(2)(j => Q(j)(i) = s)
    }

    sort(Q(0), newComp(-_.l))
    sort(Q(1), newComp(_.r))

    def calc(s: Int) = {
      val ix = Array(0, 0)

      var ans = 0L
      var p = 0
      val removed = mutable.Set[Int](N)

      def maintain(): Unit = {
        rep(2) { i =>
          while (ix(i) < N && removed.contains(Q(i)(ix(i)).id)) ix(i) += 1
        }
      }

      rep(N, s) { i =>
        maintain()
        val x = i % 2
        val s = Q(x)(ix(x))
        removed += s.id
        val (len, pos) = s.move(p)
        ans += len
        p = pos
      }
      ans + abs(p)
    }

    out.println(max(calc(0), calc(1)))
  }

  def sort[A](as: Array[A], cp: Comparator[A]): Array[A] = {
    val n = as.length
    val sorted = new java.util.PriorityQueue[A](n, cp)
    rep(n)(i => sorted.add(as(i)))
    rep(n)(i => as(i) = sorted.poll())
    as
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 115596