// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

data class Segment(val from: Int, val to: Int, val id: Int)

fun solve(n: Int, segments: List<Segment>): Long {
  val segments1 = segments.sortedWith(java.util.Comparator { s1, s2 -> s2.from - s1.from })
  val segments2 = segments.sortedWith(java.util.Comparator { s1, s2 -> s1.to - s2.to })
//  println(segments1)
//  println(segments2)
  val visited = BooleanArray(n)
  var i1 = 0
  var i2 = 0
  var ans = 0L
  var x = 0
  while (true) {
    while (visited[segments1[i1].id]) {
      i1++
      if (i1 == n) break
    }
    if (i1 == n) break

    val s1 = segments1[i1]
    // if (s1.from < x) throw RuntimeException()
    if (x !in s1.from..s1.to) {
      ans += Math.abs(s1.from - x)
      x = s1.from
    }
    visited[s1.id] = true
//    println("i1: $i1 x: $x")
//    println(visited.asList())

    while (visited[segments2[i2].id]) {
      i2++
      if (i2 == n) break
    }
    if (i2 == n) break

    val s2 = segments2[i2]
    // if (s2.to > x) throw RuntimeException()
    if (x !in s2.from..s2.to) {
      ans += Math.abs(x - s2.to)
      x = s2.to
    }
    visited[s2.id] = true
//    println("i2:$i2 x: $x")
//    println(visited.asList())
  }
  ans += Math.abs(x)
  return ans
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val segments = Array(n, {
    val (from, to) = fastReadInts(2)
    Segment(from, to, it)
  }).asList()
  val rSegments = segments.map { Segment(-it.to, -it.from, it.id) }
  val ans = solve(n, segments)
  val rAns = solve(n, rSegments)
  println(Math.max(ans, rAns))
}
