using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { static int[][] wall; static int n; static int m; static Dictionary check = new Dictionary(); static int[] rotate(int[] source) { return source.Reverse().ToArray(); } static bool wallcheck(int now) { bool ret = false; if (now == n) { ret = true; } else { bool nowcheck = true; for (int i = wall[now][0]; i <= wall[now][1]; i++) { if (check[i] == true) { nowcheck = false; break; } } if (nowcheck == true) { for (int i = wall[now][0]; i <= wall[now][1]; i++) { check[i] = true; } ret = wallcheck(now + 1); if (ret == false) { for (int i = wall[now][0]; i <= wall[now][1]; i++) { check[i] = false; } } } if (ret == false) { int bufmin = wall[now][0]; int bufmax = wall[now][1]; wall[now][0] = m - bufmax - 1; wall[now][1] = m - bufmin - 1; nowcheck = true; for (int i = wall[now][0]; i <= wall[now][1]; i++) { if (check[i] == true) { nowcheck = false; break; } } if (nowcheck == true) { for (int i = wall[now][0]; i <= wall[now][1]; i++) { check[i] = true; } ret = wallcheck(now + 1); if (ret == false) { for (int i = wall[now][0]; i <= wall[now][1]; i++) { check[i] = false; } } } bufmin = wall[now][0]; bufmax = wall[now][1]; wall[now][0] = m - bufmax - 1; wall[now][1] = m - bufmin - 1; } } return ret; } static void Main(string[] args) { int[] buf = io.r(' '); n = buf[0]; m = buf[1]; wall = io.r(n, ' '); for (int i = 0; i < m; i++) { check[i] = false; } bool ret = wallcheck(0); string output = "NO"; if (ret == true) { output = "YES"; } io.w(output); io.wflush(); } } namespace LIB { public class io { private const int WMAX = 1000; private static StringBuilder S = new StringBuilder(); public static T r() { return util.parse(r()); } public static T[] r(char s = ' ') { return r().Split(s).Select(util.parse).ToArray(); } public static T[] r(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r(); } return r; } public static T[][] r(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r(s); } return r; } private static string r() { return Console.ReadLine(); } public static void w(object v, bool lf = true) { S.Append(util.parse(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } } public static void wflush() { Console.Write(S.ToString()); S.Clear(); } } public class util { public static T parse(object value) { return (T)(Convert.ChangeType(value, typeof(T))); } } public class memo { private Dictionary R; public memo() { R = new Dictionary(); } public Result exec(Key k, Func f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; } } }