import java.util.Scanner object Problem274 { def proc(row: Int, col: Int, fromTo: Seq[(Int, Int)]): String = { val m = new collection.mutable.HashMap[Int, Int]() for (i <- 0 until col) { m += i -> 0 } fromTo foreach { case (from, to) => for (i <- from to to) { m(i) += 1 } val oppositeFrom = col - 1 - to val oppositeTo = col - 1 - from for (i <- oppositeFrom to oppositeTo) { m(i) += 1 } } if (m.forall(_._2 <= 2)) "YES" else "NO" } def main(args: Array[String]) { val sc = new Scanner(System.in) val n = sc.nextInt() val m = sc.nextInt() val fromTo = Seq.fill(n)(sc.nextInt(), sc.nextInt()) val result = proc(n, m, fromTo) println(result) } }