import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class Main { private static final String YES = "YES"; private static final String NO = "NO"; private static int n; private static int m; private static int[] blocksCount; private static List blocks; public static void main(String[] args) { Scanner cin = new Scanner(System.in); n = Integer.parseInt(cin.next()); m = Integer.parseInt(cin.next()); blocksCount = new int[(m + 1) / 2]; blocks = new ArrayList(n); for (int i = 0; i < n; i++) { int[] block = new int[2]; int begin = Integer.parseInt(cin.next()); int end = Integer.parseInt(cin.next()); block[0] = end - begin + 1; /* 180度回転したほうが開始位置が左にくるようであればその向きにしてからリストに詰める */ block[1] = Math.min(begin, m - end - 1); blocks.add(block); } cin.close(); /* リストをソートする。1.ブロック数の多いもの 2. */ Collections.sort(blocks, new Comparator() { @Override public int compare(int[] o1, int[] o2) { return o2[0] == o1[0] ? o1[1] - o2[1] : o2[0] - o1[0]; } }); execute2(); } private static void execute2() { for (int[] block : blocks) { for (int i = 0; i < block[0]; i++) { int index = block[1] + i; if (index >= m / 2) { index = m - index - 1; } if (blocksCount[index] == 2) { System.out.println(NO); System.exit(0); } else if (index == m / 2 && blocksCount[index] == 1) { System.out.println(NO); System.exit(0); } blocksCount[index]++; } } System.out.println(YES); } }