object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max (2 * v2)
  val s1 = (2 * vm + 1) max (2 * v1)

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (
    vm <= s1 && vm <= s2 && vm <= s3 &&
    like(v1, s1) && like(v2, s2) && like(v3, s3) &&
    !like(vm, s1) && !like(vm, s2) && like(vm, s3)
  ) {
    println(s1)
    println(s2)
    println(s3)
  } else {
    println("-1")
  }
}

import java.util

import scala.collection.mutable
import scala.io.StdIn

object Solution {

  //Console.setIn(new FileReader(new java.io.File("input")))
  //Console.setOut(new PrintStream(new java.io.File("output")))

  var caseNo = 1

  def doCase() : Unit = {
    val Array(f, mo, son, ma) = readIntLine()

    var l = f
    while (l <= f * 2) {
      var m = mo
      while (m < Math.min(mo * 2 + 1, l)) {
        var s = son
        while (s < Math.min(m, son * 2 + 1)) {

          if (ma * 2 >= s && ma <= s && ma * 2 < m) {
            println(l)
            println(m)
            println(s)
            return
          }

          s += 1
        }
        m += 1
      }
      l += 1
    }
    println(-1)

  }

  def main(args: Array[String]) {
    var tests = 1
    for (test <- 0 until tests) {
      doCase()
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

}

/**
  * @see http://codeforces.com/contest/907/problem/A
  */

object AMashaAndBears extends App {
  def like(a: Int, b: Int): Boolean = a <= b && 2 * a >= b

  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max v2
  val s1 = (2 * vm + 1) max (s2 + 1) max v1

  if (like(v1, s1) && like(v2, s2) && like(v3, s3) && like(vm, s3)) {
    println(s1)
    println(s2)
    println(s3)
  } else println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- c1 + 1 to 200
    c3 <- c2 + 1 to 200
  } {
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= c1 && 2 * vm < c2 && 2 * vm < c3) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- c1 + 1 to 200
    c3 <- c2 + 1 to 200
  } {
    if (v1 <= c1 && 2 * v1 >= c1 &&
      v2 <= c2 && 2 * v2 >= c2 &&
      v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= c1 && 2 * vm < c2 && 2 * vm < c3) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

import java.util

import scala.collection.mutable
import scala.io.StdIn

object Solution {

  //Console.setIn(new FileReader(new java.io.File("input")))
  //Console.setOut(new PrintStream(new java.io.File("output")))

  var caseNo = 1

  def doCase() : Unit = {
    val Array(f, mo, s, ma) = readIntLine()

    var lc = f * 2
    var mc = Math.min(lc - 1, mo * 2)
    var sc = Math.max(s, ma)
    if (s * 2 < sc || ma * 2 < sc || s < sc  || ma < sc || sc >= mc) {
      println(-1)
    } else {
      println(lc)
      println(mc)
      println(sc)
    }

  }

  def main(args: Array[String]) {
    var tests = 1
    for (test <- 0 until tests) {
      doCase()
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

}

import java.util

import scala.collection.mutable
import scala.io.StdIn

object Solution {

  //Console.setIn(new FileReader(new java.io.File("input")))
  //Console.setOut(new PrintStream(new java.io.File("output")))

  var caseNo = 1

  def doCase() : Unit = {
    val Array(f, mo, s, ma) = readIntLine()

    var lc = f * 2
    var mc = Math.min(lc - 1, mo * 2)
    var sc = Math.max(s, ma)
    if (s * 2 < sc
      || ma * 2 < sc
      || s < sc
      || ma < sc
      || sc >= mc
      || ma * 2 >= mc) {
      println(-1)
    } else {
      println(lc)
      println(mc)
      println(sc)
    }

  }

  def main(args: Array[String]) {
    var tests = 1
    for (test <- 0 until tests) {
      doCase()
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- c1 to 200
    c3 <- c2 to 200
  } {
    val cMin = Math.min(c1, Math.min(c2, c3))
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= cMin && (2 * vm < c1 || c1 == cMin) &&
        (2 * vm < c2 || c2 == cMin) && (2 * vm < c3 || c3 == cMin)) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- vm to 200
    c3 <- vm to 200
  } {
    val cMin = Math.min(c1, Math.min(c2, c3))
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= cMin && (2 * vm < c1 || c1 == cMin) &&
        (2 * vm < c2 || c2 == cMin) && (2 * vm < c3 || c3 == cMin)) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- vm to 200
    c3 <- vm to 200
  } {
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= c1 && 2 * vm < c2 && 2 * vm < c3) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- vm to 200
    c3 <- vm to 200
  } {
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * c3 >= c3 &&
      2 * vm >= c1 && 2 * vm < c2 && 2 * vm < c3) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(v3, v2, v1, vm) = readInts(4)

  for {
    c1 <- vm to 200
    c2 <- c1 + 1 to 200
    c3 <- c2 + 1 to 200
  } {
    if (v1 <= c1 && 2 * v1 >= c1 && //2 * v1 < c2 && //2 * v1 < c2 */&&
      /*v2 > c1 && */v2 <= c2 && 2 * v2 >= c2 && //2 * v2 < c3 &&
      /*v3 > c1 && v3 > c2 && */v3 <= c3 && 2 * v3 >= c3 &&
      2 * vm >= c1) {
      println(c3)
      println(c2)
      println(c1)
      System.exit(0)
    }
  }

  println(-1)
}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm) max v2
  val s1 = (2 * vm) max v1

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (like(v3, s3) && like(v2, s2) && like(v1, s1) && like(vm, s3) && !like(vm, s2) && !like(vm, s1)) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }

}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max v2
  val s1 = (2 * vm + 1) max v1

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (
    vm <= s1 && vm <= s2 && vm <= s3 &&
    like(v1, s1) && like(v2, s2) && like(v3, s3) &&
    like(vm, s1) && !like(vm, s2) && !like(vm, s3)
  ) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }
}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (s3 + 1) max v2
  val s1 = (s3 + 1) max v1

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (like(v3, s3) && like(v2, s2) && like(v1, s1) && like(vm, s3) && !like(vm, s2) && !like(vm, s1)) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }

}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max v2
  val s1 = (2 * vm + 1) max v1

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (
    vm <= s1 && vm <= s2 && vm <= s3 &&
    like(v1, s1) && like(v2, s2) && like(v3, s3) &&
    !like(vm, s1) && !like(vm, s2) && like(vm, s3)
  ) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }
}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  if ((v3 max vm) > ((2 * v3) min (2 * vm))) println("-1")
  else {
    println(v1)
    println(v2)
    println(v3 max vm)
  }
}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max v2
  val s1 = (2 * vm + 1) max v1

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (like(v3, s3) && like(v2, s2) && like(v1, s1) && like(vm, s3) && !like(vm, s2) && !like(vm, s1)) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }

}

object AA extends App {
  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max (2 * v2)
  val s1 = (2 * vm + 1) max (2 * v1)

  def like(v: Int, s: Int): Boolean = v <= s && 2 * v >= s

  if (
    vm <= s1 && vm <= s2 && vm <= s3 &&
    like(v1, s1) && like(v2, s2) && like(v3, s3) &&
    !like(vm, s1) && !like(vm, s2) && like(vm, s3)
  ) {
    println(v1)
    println(v2)
    println(v3)
  } else {
    println("-1")
  }
}

/**
  * @see http://codeforces.com/contest/907/problem/A
  */

object AMashaAndBears extends App {
  def like(a: Int, b: Int): Boolean = a <= b && 2 * a >= b

  val Array(v1, v2, v3, vm) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val s3 = v3 max vm
  val s2 = (2 * vm + 1) max v2
  val s1 = (2 * vm + 1) max v1

  if (like(v1, s1) && like(v2, s2) && like(v3, s3) && like(vm, s3)) {
    println(s1)
    println(s2)
    println(s3)
  } else println(-1)
}


object _977C extends CodeForcesApp {
  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    val n, k = io.read[Int]
    val nums = 1 +: io.read[Vector, Int](n).sorted
    val ans = if (k == n || nums(k) != nums(k+1)) {
      nums(k)
    } else {
      -1
    }
    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object 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, K = ni()
    val A = na(N)
    radixSort(A)

    val x = if (K == 0) 1 else A(K - 1)
    val x1 = if (K == N) A(K - 1) + 1 else A(K)
    if (x == x1) out.println(-1)
    else out.println(x)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  def radixSort(f: Array[Int]): Array[Int] = radixSort(f, f.length)
  def radixSort(f1: Array[Int], n: Int): Array[Int] = {
    var f = f1
    var to = Array.ofDim[Int](n)

    val b = Array.ofDim[Int](65537)
    rep(n){ i => b(1 + (f(i) & 0xffff)) += 1 }
    rep(65536, 1){ i => b(i) += b(i - 1) }
    rep(n){ i =>
      val j = f(i) & 0xffff
      to(b(j)) = f(i)
      b(j) += 1
    }
    val temp = f
    f = to
    to = temp

    java.util.Arrays.fill(b, 0)
    rep(n){ i => b(1 + (f(i) >>> 16)) += 1 }
    rep(65536, 1){ i => b(i) += b(i - 1) }
    rep(n){ i =>
      val j = f(i) >>> 16
      to(b(j)) = f(i)
      b(j) += 1
    }
    to
  }

  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 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
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object 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, K = ni()
    val A = na(N)

    def cntLe(x: Int): Int = {
      var res = 0
      rep(N) { i =>
        if (A(i) <= x) res += 1
      }
      res
    }

    def f(x: Int): Boolean = {
      cntLe(x) >= K
    }

    var l = 0
    var h = 1e9.toInt + 1
    while(h - l > 1) {
      val m = (h + l) / 2
      if (f(m)) h = m
      else l = m
    }

    val x = h
    if (cntLe(x) == K) out.println(x)
    else out.println(-1)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  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 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
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

import java.util.PriorityQueue

import scala.collection.mutable

object CE976B extends App {
  val arrayLine = readLine().split(" ")
  val n = arrayLine(0).toInt
  val k = arrayLine(1).toInt
  val string = readLine();
  val numMap = string.split(" ").map(_.toInt).sorted
  if (k == 0)
    if (numMap(0) > 1)
      print(numMap(0) - 1)
    else
      print(-1)
  else if (k == n)
    print(numMap(k - 1))
  else if (numMap(k - 1) == numMap(k))
    print(-1)
  else
    print(numMap(k - 1))
}

import scala.io.StdIn

object LessOrEqualTest {
  def main(args: Array[String]):Unit ={
//    val number = StdIn.readInt()
//    val lessOrEqual = new LessOrEqual
//    val isLessOrEqual = lessOrEqual.process(number )
//    print(isLessOrEqual)
    val nk = StdIn.readLine().split(" ").map(_.toInt)
    val elements = StdIn.readLine().split(" ").map(_.toInt)
    val elementsSorted = elements.sortWith(_ < _)
    val k = nk(1)
    val n = nk(0)

    val res = proc(k,n,elementsSorted)

    print(res)
  }

  def proc(k: Int, tam: Int, elements:Array[Int]): String ={
    if( k > tam ) return "-1"
    if (k == tam) return elements(k-1)+" "
    if(k < tam){

      if (k == 0 ){
        if (elements(0) > 1){
          return elements( 0 ) - 1+""
        }
        else return "-1"
      }

      if ( elements( k - 1 ) < elements( k ))
        {return elements(k - 1)+ ""}
    }
    return "-1"
  }
}

object C732 extends App {
  def parseIn(): (Int, Int, Array[Int]) = {
    val splitted = readLine.split(" ").map(_.toInt)
    (splitted(0), splitted(1), readLine.split(" ").map(_.toInt))
  }

  def solve(k: Int, data: Array[Int]): Int = {
    if (k == n) data.reverse.head
    else if (k != 0 & n > 1) {
      if (data(k - 1) != data(k)) data(k - 1)
      else -1
    } else {
      if (data.head > 1) {
        if (k == 0 & data.head == 1) -1
        else if (k == 0) data.head - 1
        else data.head
      } else -1
    }
  }

  val (n, k, data) = parseIn
  println(solve(k, data.sortWith(_ < _)))
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._
    import scala.collection.JavaConverters._

    val source = System.in
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val Array(n, k) = readArray().map(_.toInt)
        var a = readArray().map(_.toInt)
        a = a.sortWith(_ < _)
        if (k == n) {
            print(a(n - 1))
            return
        }

        if (k == 0) {
            if (a(0) - 1 > 0) print(a(0) - 1)
            else print(-1)
            return
        }

        if (a(k - 1) == a(k)) {
            print(-1)
            return
        }
        print(a(k - 1))
    }
}

object Problem_977C {
  // Less or Equal
  // The first line of the input contains integer numbers n and k (1≤n≤2⋅105, 0≤k≤n).
  // The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤109) — the sequence itself.

  def main(args: Array[String]) {
    val scan = scala.io.StdIn

    //Get inputs
    val inputs: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val targetArr: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val n= inputs(0)
    val k= inputs(1)

    if (k == n) {
        println(targetArr.max)
    }
    else if (k == 0) {
      if (targetArr.min == 1)
        println("-1")
      else
        println(targetArr.min - 1)
    }
    else{
      val sortedArr = targetArr.sorted
      if(sortedArr(k-1) == sortedArr(k))
        println("-1")
      else
        println(sortedArr(k-1))
    }
  }

}

object Problem_977C {
  // Less or Equal
  // The first line of the input contains integer numbers n and k (1≤n≤2⋅105, 0≤k≤n).
  // The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤109) — the sequence itself.

  def main(args: Array[String]) {
    val scan = scala.io.StdIn

    //Get inputs
    val inputs: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val targetArr: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val n= inputs(0)
    val k= inputs(1)

    if (k == n) {
      if (targetArr.max == Math.pow(10, 9))
        println("-1")
      else
        println(targetArr.max + 1)
    }
    else if (k == 0) {
      if (targetArr.min == 1)
        println("-1")
      else
        println(targetArr.min - 1)
    }
    else{
      val sortedArr = targetArr.sorted
      if(sortedArr(k-1) == sortedArr(k))
        println("-1")
      else
        println(sortedArr(k-1))
    }
  }

}

object Problem_977C {
  // Less or Equal
  // The first line of the input contains integer numbers n and k (1≤n≤2⋅105, 0≤k≤n).
  // The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤109) — the sequence itself.

  def main(args: Array[String]) {
    val scan = scala.io.StdIn

    //Get inputs
    val inputs: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val targetArr: Array[Int] = scan.readLine().split(" ").map(_.toInt)
    val n= inputs(0)
    val k= inputs(1)

    if (k == n) {
      if (targetArr.max == Math.pow(10, 9))
        println("-1")
      else
        println(targetArr.max + 1)
    }
    else if (k == 0) {
      if (targetArr.min == 0)
        println("-1")
      else
        println(targetArr.min - 1)
    }
    else{
      val sortedArr = targetArr.sorted
      if(sortedArr(k-1) == sortedArr(k))
        println("-1")
      else
        println(sortedArr(k-1))
    }
  }

}

object 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, K = ni()
    val A = na(N)

    val ms = A.min
    if (K == 0 && ms == 1) {
      out.println(-1)
    } else if (K == 0 && ms > 1) {
      out.println(1)
    } else if (K == N) {
      out.println(A(N - 1))
    } else {
      def cnt(x: Int) = {
        var s = 0
        rep(N) { i =>
          if (A(i) <= x) s += 1
        }
        s
      }

      var l = -1
      var h = N
      while(h - l > 1) {
        val m = (l + h) / 2
        if (cnt(m) < K) l = m
        else h = m
      }

      val x = h
      val ans = if (cnt(x) != K) -1 else x
      out.println(ans)
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  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 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
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object 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, K = ni()
    val A = na(N)

    def cnt(x: Int) = {
      var s = 0
      rep(N) { i =>
        if (A(i) <= x) s += 1
      }
      s
    }

    if (K == 0) {
      if (cnt(1) > 0) {
        out.println(-1)
      } else {
        out.println(1)
      }
    } else {
      var l = -1
      var h = N
      while(h - l > 1) {
        val m = (l + h) / 2
        if (cnt(m) < K) l = m
        else h = m
      }

      val x = h
      val ans = if (cnt(x) != K) -1 else x
      out.println(ans)
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  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 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
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object 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, K = ni()
    val A = na(N)

    def cnt(x: Int) = {
      var s = 0
      rep(N) { i =>
        if (A(i) <= x) s += 1
      }
      s
    }

    if (K == 0) {
      if (cnt(1) > 1) {
        out.println(-1)
      } else {
        out.println(1)
      }
    } else if (K == N) {
      out.println(A.max)
    } else {
      var l = -1
      var h = N
      while(h - l > 1) {
        val m = (l + h) / 2
        if (cnt(m) < K) l = m
        else h = m
      }

      val x = h
      val ans = if (cnt(x) != K) -1 else x
      out.println(ans)
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  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 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
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

import java.util.PriorityQueue

import scala.collection.mutable

object CE976B extends App {
  val arrayLine = readLine().split(" ")
  val n = arrayLine(0).toInt
  val k = arrayLine(1).toInt
  val string = readLine();
  val numMap = string.split(" ").map(_.toInt).sorted
  if (k == 0)
    print(numMap(0) - 1)
  else if (k == n)
    print(numMap(k - 1))
  else if (numMap(k - 1) == numMap(k))
    print(-1)
  else
    print(numMap(k - 1))
}

import scala.io.StdIn

object LessOrEqualTest {
  def main(args: Array[String]):Unit ={
//    val number = StdIn.readInt()
//    val lessOrEqual = new LessOrEqual
//    val isLessOrEqual = lessOrEqual.process(number )
//    print(isLessOrEqual)
    val nk = StdIn.readLine().split(" ").map(_.toInt)
    val elements = StdIn.readLine().split(" ").map(_.toInt)
    val elementsSorted = elements.sortWith(_ < _)
    val k = nk(1)
    if(k > 0)
      if ( elements( k - 1 ) < elements( k ))
        print( elementsSorted(k - 1) )

    print("-1")

  }
}

import scala.io.StdIn

object LessOrEqualTest {
  def main(args: Array[String]):Unit ={
//    val number = StdIn.readInt()
//    val lessOrEqual = new LessOrEqual
//    val isLessOrEqual = lessOrEqual.process(number )
//    print(isLessOrEqual)
    val nk = StdIn.readLine().split(" ").map(_.toInt)
    val elements = StdIn.readLine().split(" ").map(_.toInt)
    val elementsSorted = elements.sortWith(_ < _)
    val k = nk(1)
    if(k > 0)
      if ( elements( k - 1 ) < elements( k ))
        print( elementsSorted(k - 1) )
      else print("-1")
    else print("-1")

  }
}

import scala.io.StdIn

object LessOrEqualTest {
  def main(args: Array[String]):Unit ={
//    val number = StdIn.readInt()
//    val lessOrEqual = new LessOrEqual
//    val isLessOrEqual = lessOrEqual.process(number )
//    print(isLessOrEqual)
    val nk = StdIn.readLine().split(" ").map(_.toInt)
    val elements = StdIn.readLine().split(" ").map(_.toInt)
    val elementsSorted = elements.sortWith(_ < _)
    val k = nk(1)
    if(k > 0)
      if ( elements( k - 1 ) < elements( k ))
        print( elementsSorted(k - 1) )
      else print("-1")
    print("-1")

  }
}

object C732 extends App {
  def parseIn(): (Int, Int, Array[Int]) = {
    val splitted = readLine.split(" ").map(_.toInt)
    (splitted(0), splitted(1), readLine.split(" ").map(_.toInt))
  }

  def solve(k: Int, data: Array[Int]): Int = {
    if (k != 0) {
      if (data(k - 1) != data(k)) data(k - 1)
      else -1
    } else -1
  }

  val (n, k, data) = parseIn
  println(solve(k, data.sortWith(_ < _)))
}


/**
  * Created by ruslan on 3/4/17.
  */
object ProblemE extends App {
    import java.io.{BufferedReader, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

  override def main(args: Array[String]): Unit = {
    val br = new BufferedReader(new InputStreamReader(System.in))
    var st: StringTokenizer = null
    val out = new PrintWriter(System.out)

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

    def nextInt: Int = next.toInt

    val n = nextInt

    var result = 0
    for (i <- 1 to n) {
      result += (next match {
        case "Tetrahedron" => 4
        case "Cube" => 6
        case "Octahedron" => 8
        case "Dodecahedron" => 12
        case "Icosahedron" => 20
      })
    }
    println(result)
  }
}

object tanya extends App{
var a = readInt
var sum = 0
for(i <- 0 to a){
    var str = readLine
    if(str == "Tetrahedron"){
        sum = sum + 4
    }else if(str == "Cube"){
        sum = sum + 6
    }else if(str == "Octahedron"){
        sum = sum + 8
    }else if(str == "Dodecahedron"){
        sum = sum + 12
    }else if(str == "Icosahedron"){
        sum = sum + 20
    }
}
println(sum)
}

import java.util.Scanner

import scala.collection.immutable.HashMap

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

object A extends App {

  val sc = new Scanner(System.in)

  val sides = HashMap[String, Int](
    "Tetrahedron" -> 4,
    "Cube" -> 6,
    "Octahedron" -> 8,
    "Dodecahedron" -> 12,
    "Icosahedron" -> 20
  )

  val n = sc.nextInt()
  var total = 0
  (1 to n) foreach { _ =>
    total += sides(sc.next())
  }
  println(total)
}

object A785 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    var res = 0L
    val map = Map("Tetrahedron"->4, "Cube"->6, "Octahedron"->8, "Dodecahedron"->12, "Icosahedron"->20)
    for(_ <- 1 to n) {
      val input = read
      res += map(input)
    }
    println(res)
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

import io.StdIn._
object AntonAndHydrones {

  def main(args: Array[String]): Unit = {
    val number = readInt()
    var sum = 0
    val result = for(i <- 1 to number) yield{
      var line = readLine()
      var lineValue = line match {
        case "Tetrahedron" => 4
        case "Cube" => 6
        case "Octahedron" => 8
        case "Dodecahedron" => 12
        case "Icosahedron" => 20
      }
      sum += lineValue
    }
    println(sum)
  }

}

object _785A extends CodeForcesApp {
  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val polygons = read[Seq[String]]

    val faces = polygons sumWith {
      case "Tetrahedron" => 4
      case "Cube" => 6
      case "Octahedron" => 8
      case "Dodecahedron" => 12
      case "Icosahedron" => 20
    }

    write(faces)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

import scala.io.StdIn

object TaskA {

  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()

    def f(): Int = {
      StdIn.readLine() match {
      case "Tetrahedron" => 4
      case "Cube" => 6
      case "Octahedron" => 8
      case "Dodecahedron" => 12
      case "Icosahedron" => 20
      }
    }

    println((1 to n map (_ => f())).sum)
  }

}

import scala.io.StdIn

object Codeforces785A extends App {
  var n = StdIn.readLine().toInt
  var s = 0
  while (n > 0) {
    n -= 1
    val p = StdIn.readLine()
    if (p == "Tetrahedron") s += 4
    if (p == "Cube") s += 6
    if (p == "Octahedron") s += 8
    if (p == "Dodecahedron") s += 12
    if (p == "Icosahedron") s += 20
  }
  print(s)
}

import scala.io.StdIn._

object Main2 extends App {
  val figureNumber = readInt()
  val res = 0.until(figureNumber).map(_ => readLine()).map {
    case "Tetrahedron" => 4
    case "Cube" => 6
    case "Octahedron" => 8
    case "Dodecahedron" => 12
    case "Icosahedron" => 20
  }.sum
  println(res)
}

import java.io._
import java.util.StringTokenizer

import scala.language.postfixOps

object TaskA extends App {
  val ir = new InputReader(System.in)
  val n = ir.nextInt

  val m = Map("Tetrahedron" -> 4, "Cube" -> 6, "Octahedron" -> 8, "Dodecahedron" -> 12, "Icosahedron" -> 20)

  println(1 to n map { _ => ir.nextString } map m sum)
}

class InputReader(val stream: InputStream) {
  val reader = new BufferedReader(new InputStreamReader(stream))
  var stt: StringTokenizer = _

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

  def nextInt: Int = nextString.toInt
}

import scala.io.StdIn._

object Solution {

	var n = readLine.toInt
    var shapes = Array.fill[String](n)(null)
    for(i <- 0 until n) shapes(i) = readLine

	def main(args:Array[String]):Unit = {

		var ret = 0

        for(i <- 0 until n) {
            var sides = shapes(i) match {
                case "Tetrahedron" => 4
				case "Cube" => 6
				case "Octahedron" => 8
				case "Dodecahedron" => 12
				case "Icosahedron" => 20
            }
			ret += sides
        }

		println(ret)
	}

}

/**
  * Created by ruslan on 3/4/17.
  */
object ProblemE extends App {
    import java.io.{BufferedReader, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

  override def main(args: Array[String]): Unit = {
    val br = new BufferedReader(new InputStreamReader(System.in))
    var st: StringTokenizer = null
    val out = new PrintWriter(System.out)

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

    def nextInt: Int = next.toInt

    val n = nextInt

    var result = 0
    for (i <- 1 to n) {
      result += (next match {
        case "Tetrahedron" => 4
        case "Cube" => 4
        case "Octahedron" => 8
        case "Dodecahedron" => 12
        case "Icosahedron" => 20
      })
    }
    println(result)
  }
}


object Solution {
  def main(args: Array[String]) {
    val r = new Reader()
    val n, k, m = r.read[Int]

    import collection.mutable.{ ArrayBuffer, HashMap, HashSet }
    var ws = new HashMap[String, Int]()

    for (i <- 0 to n - 1) {
      ws(r.read[String]) = i
    }

    val cs = r.read[Array[Long]](n)
    var gs = ArrayBuffer.fill(k)(Long.MaxValue)
    var gs2 = ArrayBuffer.fill(n)(0)

    for (i <- 0 to k - 1) {
      val s = r.read[Int]

      for (_ <- 1 to s) {
        val e = r.read[Int] - 1

        gs(i) = math.min(gs(i), cs(e))
        gs2(e) = i
      }
    }

    val ws2 = r.read[Array[String]](m)
    println(ws2.map{ w => gs(gs2(ws(w))) }.sum)
  }
}

import java.io.{ BufferedReader, InputStreamReader }
import java.util.StringTokenizer

class Reader(br: BufferedReader) {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))

  def this() = this(new InputStreamReader(System.in))

  def read[A](implicit read: Reader.Read[A]): A = read.apply(this)

  val tokenizer = new Tokenizer(br)
}

object Reader {
  class Read[A](val apply: Reader => A) {}

  object Read {
    implicit val int: Read[Int] = new Read(_.tokenizer.next.toInt)
    implicit val long: Read[Long] = new Read(_.tokenizer.next.toLong)
    implicit val double: Read[Double] = new Read(_.tokenizer.next.toDouble)
    implicit val string: Read[String] = new Read(_.tokenizer.next)

    implicit def tuple[A: Read, B: Read]: Read[(A, B)] = new Read(r => (r.read[A], r.read[B]))

    import scala.collection.generic.CanBuildFrom

    // what the f*ck??
    implicit def t[T[A], A: Read](n: Int)(implicit bf: CanBuildFrom[Nothing, A, T[A]]): Read[T[A]] =
      new Read(r => Iterator.continually(r.read[A]).take(n).to[T])
  }
}

class Tokenizer(br: BufferedReader) extends Iterator[String] {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))

  def hasNext = hasMoreTokens || {
    if (tokenizers.hasNext) {
      tokenizers.next()
      hasMoreTokens
    } else false
  }

  def next() = if (hasNext) { tokenizers.head.nextToken } else null

  private def hasMoreTokens = tokenizers.headOption.map(_.hasMoreTokens()).getOrElse(false)

  private val tokenizers =
    Iterator.continually(br.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._

    val source = System.in
    //new FileInputStream("D://in.txt")
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val Array(n, k, m) = readArray().map(_.toInt)
        val _s = readArray()
        var s = new Array[(String, Int)](n)
        for (i <- 0 until n) s(i) = ((_s(i), i))
        val a = readArray().map(_.toInt)
        var f = new Array[Array[Int]](k)
        val g = new mutable.HashMap[Int, Int]()

        for (i <- 0 until k) {
            val x = readArray().map(_.toInt)
            f(i) = new Array(x(0))
            for (j <- 0 until x(0)) {
                f(i)(j) = x(j + 1) - 1
                g += x(j + 1) - 1 -> i
            }
        }

        val _s2 = readArray()
        var s2 = new Array[(String, Int)](m)
        for (i <- 0 until m) s2(i) = ((_s2(i), i))

        var (x, y) = (0, 0)
        val index = new Array[Int](k)
        s = s.sortWith(_._1 < _._1)
        s2 = s2.sortWith(_._1 < _._1)
        f = f.map(_.sortWith(a(_) < a(_)))

        var res = 0L
        while (x < s.size && y < s2.size) {
            if (s(x)._1 == s2(y)._1) {
                val id = s(x)._2
                res += a(f(g(id))(0))
                index(g(id)) += 1

                y += 1
            } else x += 1
        }

        print(res)
    }
}

object Solution {
  def main(args: Array[String]) {
    val r = new Reader()
    val n, k, m = r.read[Int]

    import collection.mutable.{ ArrayBuffer, HashMap, HashSet }
    var ws = new HashMap[String, Int]()

    for (i <- 0 to n - 1) {
      ws(r.read[String]) = i
    }

    val cs = r.read[Array[Int]](n)
    var gs = ArrayBuffer.fill(k)(Int.MaxValue)
    var gs2 = ArrayBuffer.fill(n)(0)

    for (i <- 0 to k - 1) {
      val s = r.read[Int]

      for (_ <- 1 to s) {
        val e = r.read[Int] - 1

        gs(i) = math.min(gs(i), cs(e))
        gs2(e) = i
      }
    }

    val ws2 = r.read[Array[String]](m)
    println(ws2.map{ w => gs(gs2(ws(w))) }.sum)
  }
}

import java.io.{ BufferedReader, InputStreamReader }
import java.util.StringTokenizer

class Reader(br: BufferedReader) {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))

  def this() = this(new InputStreamReader(System.in))

  def read[A](implicit read: Reader.Read[A]): A = read.apply(this)

  val tokenizer = new Tokenizer(br)
}

object Reader {
  class Read[A](val apply: Reader => A) {}

  object Read {
    implicit val int: Read[Int] = new Read(_.tokenizer.next.toInt)
    implicit val long: Read[Long] = new Read(_.tokenizer.next.toLong)
    implicit val double: Read[Double] = new Read(_.tokenizer.next.toDouble)
    implicit val string: Read[String] = new Read(_.tokenizer.next)

    implicit def tuple[A: Read, B: Read]: Read[(A, B)] = new Read(r => (r.read[A], r.read[B]))

    import scala.collection.generic.CanBuildFrom

    // what the f*ck??
    implicit def t[T[A], A: Read](n: Int)(implicit bf: CanBuildFrom[Nothing, A, T[A]]): Read[T[A]] =
      new Read(r => Iterator.continually(r.read[A]).take(n).to[T])
  }
}

class Tokenizer(br: BufferedReader) extends Iterator[String] {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))

  def hasNext = hasMoreTokens || {
    if (tokenizers.hasNext) {
      tokenizers.next()
      hasMoreTokens
    } else false
  }

  def next() = if (hasNext) { tokenizers.head.nextToken } else null

  private def hasMoreTokens = tokenizers.headOption.map(_.hasMoreTokens()).getOrElse(false)

  private val tokenizers =
    Iterator.continually(br.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._

    val source = System.in
    //new FileInputStream("D://in.txt")
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val Array(n, k, m) = readArray().map(_.toInt)
        val _s = readArray()
        var s = new Array[(String, Int)](n)
        for (i <- 0 until n) s(i) = ((_s(i), i))
        val a = readArray().map(_.toInt)
        var f = new Array[Array[Int]](k)
        val g = new mutable.HashMap[Int, Int]()

        for (i <- 0 until k) {
            val x = readArray().map(_.toInt)
            f(i) = new Array(x(0))
            for (j <- 0 until x(0)) {
                f(i)(j) = x(j + 1) - 1
                g += x(j + 1) - 1 -> i
            }
        }

        val _s2 = readArray()
        var s2 = new Array[(String, Int)](m)
        for (i <- 0 until m) s2(i) = ((_s2(i), i))

        var (x, y) = (0, 0)
        val index = new Array[Int](k)
        s = s.sortWith(_._1 < _._1)
        s2 = s2.sortWith(_._1 < _._1)
        f = f.map(_.sortWith(a(_) < a(_)))

        var res = 0
        while (x < s.size && y < s2.size) {
            if (s(x)._1 == s2(y)._1) {
                val id = s(x)._2
                res += a(f(g(id))(0))
                index(g(id)) += 1

                y += 1
            } else x += 1
        }

        print(res)
    }
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._

    val source = System.in
    //new FileInputStream("D://in.txt")
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val Array(n, k, m) = readArray().map(_.toInt)
        val s = readArray()
        val a = readArray().map(_.toInt)
        var f = new Array[Array[Int]](k)
        val g = new mutable.HashMap[Int, Int]()

        for (i <- 0 until k) {
            val x = readArray().map(_.toInt)
            f(i) = new Array(x(0))
            for (j <- 0 until x(0)) {
                f(i)(j) = x(j + 1) - 1
                g += x(j + 1) - 1 -> i
            }
        }

        val s2 = readArray()

        var (x, y) = (0, 0)
        val index = new Array[Int](k)
        f = f.map(_.sortWith(a(_) < a(_)))

        var res = 0
        while (x < s.size && y < s2.size) {
            if (s(x) == s2(y)) {
                res += a(f(g(x))(index(g(x))))
                index(g(x)) += 1

                x += 1
                y += 1
            } else x += 1
        }

        print(res)
    }
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._

    val source = System.in
    //new FileInputStream("D://in.txt")
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val Array(n, k, m) = readArray().map(_.toInt)
        val _s = readArray()
        var s = new Array[(String, Int)](n)
        for (i <- 0 until n) s(i) = ((_s(i), i))
        val a = readArray().map(_.toInt)
        var f = new Array[Array[Int]](k)
        val g = new mutable.HashMap[Int, Int]()

        for (i <- 0 until k) {
            val x = readArray().map(_.toInt)
            f(i) = new Array(x(0))
            for (j <- 0 until x(0)) {
                f(i)(j) = x(j + 1) - 1
                g += x(j + 1) - 1 -> i
            }
        }

        val _s2 = readArray()
        var s2 = new Array[(String, Int)](m)
        for (i <- 0 until m) s2(i) = ((_s2(i), i))

        var (x, y) = (0, 0)
        val index = new Array[Int](k)
        s = s.sortWith(_._1 < _._1)
        s2 = s2.sortWith(_._1 < _._1)
        f = f.map(_.sortWith(a(_) < a(_)))

        var res = 0
        while (x < s.size && y < s2.size) {
            if (s(x)._1 == s2(y)._1) {
                val id = s(x)._2
                res += a(f(g(id))(index(g(id))))
                index(g(id)) += 1

                x += 1
                y += 1
            } else x += 1
        }

        print(res)
    }
}


object A681 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = Array.fill(n){
      val tl = tokenizeLine
      tl.nextToken()
      (tl.nextToken().toInt, tl.nextToken().toInt)
    }
    if(in.exists{case (b, a) => b >= 2400 && a > b}) {
      println("YES")
    } else {
      println("NO")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  if (lines.take(n).map(_.split(' ').drop(1).map(_.toInt)).exists{
    case Array(a, b) => a >= 2400 && b > a
  })
    println("YES")
  else
    println("NO")
}

object A681 extends App {
  var n = readInt
  var result = "NO"
  while(n > 0) {
    val s = readLine.split(" ")

    if(s(1).toInt >= 2400 && s(2).toInt > s(1).toInt) {
      result = "YES"
      n = 0
    }

    n = n - 1
  }

  print(result)
}


import java.util.InputMismatchException
import java.io.InputStream
import scala.collection

/**
 * Created by hama_du on 2014/06/21.
 */
object ProblemC extends App {
  /**
   * fast IO
   */
  class InputReader(stream: InputStream) {
    val buf = new Array[Byte](1024)
    var curChar = 0
    var numChars = 0

    def next(): Int = {
      if (numChars == -1)
        throw new InputMismatchException();
      if (curChar >= numChars) {
        curChar = 0;
        numChars = stream.read(buf);
        if (numChars <= 0) {
          -1;
        }
      }
      val res = buf(curChar)
      curChar += 1
      res
    }

    def nextLong(): Long = {
      var c = next()
      while (isSpaceChar(c)) {
        c = next()
      }
      var sgn = 1
      if (c == '-') {
        sgn = -1
        c = next()
      }
      var res = 0L
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException()
        res *= 10
        res += c - '0'
        c = next()
      } while (!isSpaceChar(c))
      res * sgn
    }

    def nextInt(): Int = {
      nextLong.toInt
    }

    def isSpaceChar(c: Int) = {
      c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
  }

  /**
   * solution
   */
  def solve(a: Array[Long]): Long = {
    val n = a.length
    if (n <= 2) {
      return 0
    }

    val stack = new collection.mutable.Stack[Long]()
    val score = a.foldLeft(0L)((score, top) => {
      var nextScore = score
      while (stack.size >= 2 && stack(1) >= stack(0) && stack(0) <= top) {
        nextScore += Math.min(top, stack(1))
        stack.pop()
      }
      stack.push(top)
      nextScore
    })
    score + stack.toArray.sorted.dropRight(2).sum
  }

  val in = new InputReader(System.in)
  val n = in.nextInt()
  val a = (0 until n).map(_ => in.nextLong()).toArray
  println(solve(a))
}

import java.util.InputMismatchException
import java.io.InputStream
import scala.collection

/**
 * Created by hama_du on 2014/06/21.
 */
object ProblemC extends App {
  /**
   * fast IO
   */
  class InputReader(stream: InputStream) {
    val buf = new Array[Byte](1024)
    var curChar = 0
    var numChars = 0

    def next(): Int = {
      if (numChars == -1)
        throw new InputMismatchException();
      if (curChar >= numChars) {
        curChar = 0;
        numChars = stream.read(buf);
        if (numChars <= 0) {
          -1;
        }
      }
      val res = buf(curChar)
      curChar += 1
      res
    }

    def nextLong(): Long = {
      var c = next()
      while (isSpaceChar(c)) {
        c = next()
      }
      var sgn = 1
      if (c == '-') {
        sgn = -1
        c = next()
      }
      var res = 0L
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException()
        res *= 10
        res += c - '0'
        c = next()
      } while (!isSpaceChar(c))
      res * sgn
    }

    def nextInt(): Int = {
      nextLong.toInt
    }

    def isSpaceChar(c: Int) = {
      c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
  }

  def solve(a: Array[(Long,Int)]): Long = {
    val n = a.length
    if (n <= 2) {
      return 0
    }

    val done = new Array[Boolean](n)
    val stack = new collection.mutable.Stack[(Long,Int)]()
    val score = a.foldLeft(0L)((score, topWithIndex) => {
      val (top,_) = topWithIndex
      var nextScore = score
      while (stack.size >= 2 && stack(1)._1 >= stack(0)._1 && stack(0)._1 <= top) {
        nextScore += Math.min(top, stack(1)._1)
        val removed = stack.pop()
        done(removed._2) = true
      }
      stack.push(topWithIndex)
      nextScore
    })
    score + a.filterNot(ai => done(ai._2)).map(ai => ai._1).sorted.dropRight(2).sum
  }

  val in = new InputReader(System.in)
  val n = in.nextInt()
  val a = (0 until n).map(_ => in.nextLong()).toArray.zipWithIndex
  println(solve(a))
}

import java.util.InputMismatchException
import java.io.InputStream

/**
 * Created by hama_du on 2014/06/21.
 */
object ProblemC extends App {
  /**
   * fast IO
   */
  class InputReader(stream: InputStream) {
    val buf = new Array[Byte](1024)
    var curChar = 0
    var numChars = 0

    def next(): Int = {
      if (numChars == -1)
        throw new InputMismatchException();
      if (curChar >= numChars) {
        curChar = 0;
        numChars = stream.read(buf);
        if (numChars <= 0) {
          -1;
        }
      }
      val res = buf(curChar)
      curChar += 1
      res
    }

    def nextLong(): Long = {
      var c = next()
      while (isSpaceChar(c)) {
        c = next()
      }
      var sgn = 1
      if (c == '-') {
        sgn = -1
        c = next()
      }
      var res = 0L
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException()
        res *= 10
        res += c - '0'
        c = next()
      } while (!isSpaceChar(c))
      res * sgn
    }

    def nextInt(): Int = {
      nextLong.toInt
    }

    def isSpaceChar(c: Int) = {
      c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
  }

  def solve(a: Array[(Long,Int)]): Long = {
    val n = a.length
    if (n <= 2) {
      return 0
    }

    val done = new Array[Boolean](n)
    val score = a.foldLeft((-2L, -1L, 0L))((lcs, rightWithIndex) => {
      val (left, center, score) = lcs
      val (right,index) = rightWithIndex
      if (left >= center && center <= right) {
        done(index-1) = true
        (left, right, score + Math.min(left, right))
      } else {
        (center, right, score)
      }
    })._3
    score + a.filterNot(ai => done(ai._2)).map(ai => ai._1).sorted.dropRight(2).sum
  }

  val in = new InputReader(System.in)
  val n = in.nextInt()
  val a = (0 until n).map(_ => in.nextLong()).toArray.zipWithIndex
  println(solve(a))
}


object Main {
  def main(args: Array[String]) {
    val n = readLine().toInt
    var best = 0
    for (_ <- 1 to n) {
      val Array(k, a) = readLine().split(" ").map(_.toInt)
      var need = k + 1;
      var c:Long = 4
      while (a > c) {
        need = need + 1
        c *= 4
      }
      if (need > best) {
        best = need
      }
    }
    println(best)
  }
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(x => x(0)).map(p => (p(0), p(1)))
  def cnt(k: Int, num: Int) =
    if (k >= 16) (if (num != 0) 1 else 0) else (num - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, List(r._2, cnt(r._1 - l._1, l._2)).max))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println(List(ans, input(n-1)._1 + 1).max)
}

import collection.mutable.Queue

object test6 extends App {
    val getCount=(count:Double, layer:Int)=>(count/math.pow(4,layer)).ceil toInt

    //println(getCount(17,2))

    val n=readLine.toInt
    var arr=(for(i<-0 until n) yield readLine.split(" ").map(_.toInt) toArray) sortBy {a=>a(0)}

    var count=arr(0)(1)
    for(i<- 1 until arr.length){
        count=math.max(arr(i)(1),getCount(count, arr(i)(0)-arr(i-1)(0)))
    }

    var i=arr.last.head
    while(count>1) {count=getCount(count,1);i+=1}

    println(math.max(i,arr.last.head+1))
}

object test6 extends App {
    val getCount=(count:Double, layer:Int)=>(count/math.pow(4,layer)).ceil toInt

    val n=readLine.toInt
    var arr=(for(i<-0 until n) yield readLine.split(" ").map(_.toInt) toArray) sortBy {a=>a(0)}

    var count=arr(0)(1)
    for(i<- 1 until arr.length){
        count=math.max(arr(i)(1),getCount(count, arr(i)(0)-arr(i-1)(0)))
    }

    val ans=arr.last.head+((math.log(count)/math.log(4)).ceil toInt)
    println(math.max(ans,arr.last.head+1))
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(p => p(1)).map(p => (p(0), p(1)))
  def cnt(k: Int, n: Int) = (n - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, List(r._2, cnt(r._1 - l._1, l._2)).max))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println( if (input.length == 1 && input(0)._2 == 1) input(0)._1 + 1 else ans)
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(p => p(1)).map(p => (p(0), p(1)))
  def cnt(k: Int, n: Int) = (n - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, r._2 + cnt(r._1 - l._1, l._2)))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println( if (input.length == 1 && input(0)._2 == 1) input(0)._1 + 1 else ans)
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(p => p(1)).map(p => (p(0), p(1)))
  def cnt(k: Int, n: Int) = (n - 1 + (1 << (2 * k))) >> (2 * k)
  var (k, ans) = input.reduceLeft((l, r) => (r._1, r._2 + cnt(r._1 - l._1, l._2)))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println(ans)
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(p => p(1)).map(p => (p(0), p(1)))
  def cnt(k: Int, n: Int): Int = (n - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, r._2 + cnt(r._1 - l._1, l._2)))
  while (k != 1) {
    ans += 1
    k = (k + 3) / 4
  }
  println(ans)
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(x => x(0)).map(p => (p(0), p(1)))
  def cnt(k: Int, num: Int) = (num - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, List(r._2, cnt(r._1 - l._1, l._2)).max))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println(if (input.length == 1 && input(0)._2 == 1) input(0)._1 + 1 else ans)
}

object cf165c extends App {
  val n = readLine.toInt
  val input = (1 to n).map(n => readLine.split(' ').map(_.toInt)).sortBy(x => x(0)).map(p => (p(0), p(1)))
  def cnt(k: Int, num: Int) =
    if (k >= 16) (if (num != 0) 1 else 0) else (num - 1 + (1 << (2 * k))) >> (2 * k)
  var (ans, k) = input.reduceLeft((l, r) => (r._1, List(r._2, cnt(r._1 - l._1, l._2)).max))
  while (k != 1) {
    ans += 1
    k = (k + 3) >> 2
  }
  println(if (input.length == 1 && input(0)._2 == 1) input(0)._1 + 1 else ans)
}

import collection.mutable.Queue

object test6 extends App {
    val n=readLine.toInt
    var arr=(for(i<-0 until n) yield readLine.split(" ").map(_.toInt) toArray) sortBy {a=>a(0)}

    //for(i<-0 until n) println(arr(i).mkString(","))
    val getCount=(count:Int)=>count/4 + (if(count%4==0) 0 else 1)
    var count=0
    var j=0
    for(i<-0 to arr.last.head){
        if(arr(j)(0)==i){
            count=math.max(getCount(count), arr(j).last)
            j+=1
        }
        else count=getCount(count)
    }

    var i=arr.last.head
    while(count>1) {count=getCount(count);i+=1}
    println(i)
}

import collection.mutable.Queue

object test6 extends App {
    val n=readLine.toInt
    var arr=(for(i<-0 until n) yield readLine.split(" ").map(_.toInt) toArray) sortBy {a=>a(0)}

    //for(i<-0 until n) println(arr(i).mkString(","))
    val getCount=(count:Int)=>count/4 + (if(count%4==0) 0 else 1)
    var count=0
    var j=0
    for(i<-0 to arr.last.head){
        if(arr(j)(0)==i){
            count=math.max(getCount(count), arr(j).last)
            j+=1
        }
        else count=getCount(count)
    }

    var i=arr.last.head
    while(count>1) {count=getCount(count);i+=1}

    println(if(i==arr.last.head) i+1 else 1)
}

object test6 extends App {
    val getCount=(count:Double, layer:Int)=>(count/math.pow(4,layer)).ceil toInt

    val n=readLine.toInt
    var arr=(for(i<-0 until n) yield readLine.split(" ").map(_.toInt) toArray) sortBy {a=>a(0)}

    var count=arr(0)(1)
    for(i<- 1 until arr.length){
        count=math.max(arr(i)(1),getCount(count, arr(i)(0)-arr(i-1)(0)))
    }

    val ans=arr.last.head+(math.log(count)/math.log(4) toInt)
    println(math.max(ans,arr.last.head+1))
}


object P032A extends App {
  def upper(a: Array[Int], pos: Int, h: Int):Int = {
    var i = pos
    val b = a(i) + h
    var j = a.length - 1
    if (a(j) <= b) return j;
    while (j > i + 1) {
      val mid = (i + j) / 2
      if (a(mid) <= b) i = mid
      else             j = mid
    }
    return i
  }
  def lower(a: Array[Int], pos:Int, h: Int):Int = {
    var i = 0
    var j = pos
    val b = a(j) - h
    if (a(i) >= b) return i
    while (j > i + 1) {
      val mid = (i + j) / 2
      if (a(mid) < b) i = mid
      else            j = mid
    }
    return j;
  }

  val param = readLine.split(' ').map(_.toInt)
  val a = readLine.split(' ').map(_.toInt).sorted
  var result = 0
  for (i <- 0 to param(0)-1) {
    result += upper(a, i, param(1)) - lower(a, i, param(1))
  }
  print(result)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, d) = in.next().split(' ').map(_.toInt)
  val line = in.next().split(' ').map(_.toInt)

  println(line.indices.foldLeft(0) {
    case (acc, i) => acc + line.indices.count(j => i != j && Math.abs(line(i) - line(j)) <= d)
    })
}

object A32 {
  import IO._
  import collection.{mutable => cu}
  def main(args: Array[String]): Unit = {
    val Array(n, d) = readInts(2)
    val num = readLongs(n).sorted
    var res = 0
    for(i <- 0 until n; j <- i+1 until n) {
      if(num(j)-num(i) <= d)
        res += 1
    }
    out.println(2*res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }
}

import scala.io._
import scala.collection.mutable._
import java.util.StringTokenizer

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var Array(n, d) = readLine.split(" ").map(_.toInt);
    var arr = readLine.split(" ").map(_.toInt);
    var result = 0;
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        if (i != j) {
    	  if (math.abs(arr(i) - arr(j)) <= d) {
    	    result += 1;
    	  }
        }
      }
    }
    println(result);
  }

}