import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[pos][spa][last] != -1)
            return dp[pos][spa][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[pos][spa][last] = -2;

        if(c1 == -2)
            return dp[pos][spa][last] = c2;

        if(c2 == -2)
            return dp[pos][spa][last] = c1;

        return dp[pos][spa][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit((a>=count || b>=count) ? 0 : -1);

        dp = new int[n+1][a+1][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<a+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }
        for(int j = 0; j<a+1; j++) {
            dp[0][j] = new int[3];
            Arrays.fill(dp[0][j], -1);
        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = false;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[spa][pos][last] != -1)
            return dp[spa][pos][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[spa][pos][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[spa][pos][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[spa][pos][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[spa][pos][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[spa][pos][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[spa][pos][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[spa][pos][last] = -2;

        if(c1 == -2)
            return dp[spa][pos][last] = c2;

        if(c2 == -2)
            return dp[spa][pos][last] = c1;

        return dp[spa][pos][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit((a>=count || b>=count) ? 0 : -1);

        dp = new int[a+1][n+1][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<n+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }
        for(int j = 0; j<a+1; j++) {
            dp[j][0] = new int[3];
            Arrays.fill(dp[j][0], -1);
        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[last][pos][spa] != -1)
            return dp[last][pos][spa];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[last][pos][spa] = 0;
                } else if(spb >= h[pos]) {
                    return dp[last][pos][spa] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[last][pos][spa] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[last][pos][spa] = 0;
                } else if(spa >= h[pos]) {
                    return dp[last][pos][spa] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[last][pos][spa] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[last][pos][spa] = -2;

        if(c1 == -2)
            return dp[last][pos][spa] = c2;

        if(c2 == -2)
            return dp[last][pos][spa] = c1;

        return dp[last][pos][spa] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit((a>=count || b>=count) ? 0 : -1);

        dp = new int[3][n+1][a+1];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<n+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }
//      for(int j = 0; j<a+1; j++) {
//          dp[j][0] = new int[3];
//          Arrays.fill(dp[j][0], -1);
//      }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[pos][spa][last] != -1)
            return dp[pos][spa][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[pos][spa][last] = -2;

        if(c1 == -2)
            return dp[pos][spa][last] = c2;

        if(c2 == -2)
            return dp[pos][spa][last] = c1;

        return dp[pos][spa][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit(0);

        dp = new int[n+1][a+1][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<a+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[pos][spa][last] != -1)
            return dp[pos][spa][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[pos][spa][last] = -2;

        if(c1 == -2)
            return dp[pos][spa][last] = c2;

        if(c2 == -2)
            return dp[pos][spa][last] = c1;

        return dp[pos][spa][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit((a>=count || b>=count) ? 0 : -1);

        dp = new int[n+1][a+1][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<a+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define mp(a , b) make_pair(a , b)
using namespace std;
const int N = 205;
int n , h[N];
int a , b , sum[N];
int dp[N][40005][2];
int main () {
    freopen ("input.txt" , "r" , stdin);
    freopen ("output.txt" , "w" , stdout);
    while (scanf ("%d" , &n) != EOF) {
        scanf ("%d %d " , &a , &b);
        sum[0] = 0;
        for (int i = 1 ; i <= n ; i ++) {
            scanf ("%d" , &h[i]);
            sum[i] = sum[i - 1] + h[i];
        }printf("A");
        h[0] = 0;
        memset (dp , 0x11 , sizeof(dp));
        dp[0][0][0] = 0;
        dp[0][0][1] = 0;
        for (int i = 0 ; i < n ; i ++) {
            for (int j = 0 ; j <= a ; j ++) {
                for (int k = 0 ; k < 2 ; k ++) {
                    if (dp[i][j][k] == 0x11111111) continue;
                    int red = j , green = sum[i] - j;
                    if (green < 0 || green > b) continue;
                    if (red + h[i + 1] <= a) {
                        dp[i + 1][j + h[i + 1]][0] = min (dp[i + 1][j + h[i + 1]][0] , dp[i][j][k] + (k == 0 ? 0 : min (h[i + 1] , h[i])));
                    }
                    if (green + h[i + 1] <= b) {
                        dp[i + 1][j][1] = min (dp[i + 1][j][1] , dp[i][j][k] + (k == 1 ? 0 : min (h[i] , h[i + 1])));
                    }
                }
            }
        }
        int ans = 0x11111111;
        for (int i = 0 ; i <= a ; i ++)
            for (int j = 0 ; j < 2 ; j ++)
                ans = min (ans , dp[n][i][j]);
        if (ans >= 0x11111111) puts("-1");
        else printf("%d\n" , ans);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define MAXN 200
#define MAXAB 40000
#define MAXH 200
#define INF 10000000
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, a, b, h[MAXN], dp[MAXAB + MAXH + 2][2];
    scanf("%d%d%d", &n, &a, &b);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", h + i);
    }
    fill(&dp[0][0], &dp[MAXAB + MAXH + 2][0], INF);
    int sum = h[0];
    dp[a - sum][0] = 0;
    dp[a][1] = 0;
    for (int i = 1; i < n; ++i)
    {
        sum += h[i];
        for (int j = 0; j <= a; ++j)
        {
            if (sum - (a - j) <= b)
                dp[j][1] = min(dp[j][1], dp[j][0] + min(h[i], h[i - 1]));
            else
                dp[j][1] = INF;
            dp[j][0] = min(dp[j + h[i]][0], dp[j + h[i]][1] + min(h[i], h[i - 1]));
        }
    }
    int res = INF;
    for (int i = 0; i <= a; ++i)
    {
        res = min(res, min(dp[i][0], dp[i][1]));
    }
    if (res >= INF) printf("-1\n");
    else printf("%d\n", res);
    return 0;
}


#include <cstdio>
#include <algorithm>
#define MAXN 200
#define MAXAB 40000
#define MAXH 200
#define INF 10000000
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, a, b, h[MAXN], dp[MAXAB + MAXH + 2][2];
    scanf("%d%d%d", &n, &a, &b);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", h + i);
    }
    fill(&dp[0][0], &dp[MAXAB + MAXH + 2][0], INF);
    int sum = h[0];
    if (a >= sum) dp[a - sum][0] = 0;
    if (b >= sum) dp[a][1] = 0;
    for (int i = 1; i < n; ++i)
    {
        sum += h[i];
        for (int j = 0; j <= a; ++j)
        {
            if (sum - (a - j) <= b)
                dp[j][1] = min(dp[j][1], dp[j][0] + min(h[i], h[i - 1]));
            else
                dp[j][1] = INF;
            dp[j][0] = min(dp[j + h[i]][0], dp[j + h[i]][1] + min(h[i], h[i - 1]));
        }
    }
    int res = INF;
    for (int i = 0; i <= a; ++i)
    {
        res = min(res, min(dp[i][0], dp[i][1]));
    }
    if (res >= INF) printf("-1\n");
    else printf("%d\n", res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                flag=1;
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m && a[0][0]=0)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                flag=1;
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m && a[0][0]==0)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m && a[0][0]==0)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                flag=1;
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m a[0][0]==0)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                flag=1;
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        if(x==m)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define inf (int)1e9
#define pb push_back
#define mp make_pair
#define gcd(a,b) (__gcd((a),(b)))
#define print(x) cout << (x) << endl

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }
    int i = 2;
    while (i*i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

int main()
{
    int n,m,x,flag=0,pm=0;
    cin>>n>>m;
    int a[n][2];
    rep(i,n)
    {
        rep(j,2)
        {
            cin>>a[i][j];
        }
    }
    x=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][1]>x)
        {
            if(a[i][0]<=x)
            {
                x=a[i][1];
            }
            else
            {
                cout<<"NO";
                break;
            }
        }
        if(x==m)
        {
            cout<<"YES";
            break;
        }
    }
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }

    int j = 0;
    int isIt = false;

    while(j < n && v[j-1].second < m){
        if(v[j].second >= m)isIt = true;
        if(j < n && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b, furt = -1;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        if(b > furt){
            v.push_back({a, b});
            furt = b;
        }

    }

    sort(v.begin(), v.end());
    int j = 0;
    bool isIt = false;
    n = v.size();

    //for(int i=0; i<n; i++)cout << v[i].first << " " << v[i].second << "\n";

    while(j < n){

        if(v[j].second >= m){
            isIt = true;
            break;
        }
        if(j < n-1 && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }

    int j = 0;
    bool isIt = false;

    while(j < n){
        if(v[j].second >= m){
            isIt = true;
            break;
        }
        if(j < n-1 && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b, furt = -1;
    vector< pair<int, int> > v = {{0, 0}};

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        if(b > furt){
            v.push_back({a, b});
            furt = b;
        }

    }

    sort(v.begin(), v.end());
    int j = 0;
    bool isIt = false;
    n = v.size();

    //for(int i=0; i<n; i++)cout << v[i].first << " " << v[i].second << "\n";

    while(j < n){

        if(v[j].second >= m){
            isIt = true;
            break;
        }
        if(j < n-1 && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }

    int j = 0;
    int isIt = false;

    while(j < n && v[j-1].second < m){
        if(v[j].second >= m)isIt = true;
        if(j < n-1 && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }

    sort(v.begin(), v.end());
    int j = 0;
    bool isIt = false;

    while(j < n){

        if(v[j].second >= m){
            isIt = true;
            break;
        }
        if(j < n-1 && v[j].second < v[j+1].first)break;
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>

#define INF 1e9

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    vector< pair<int, int> > v;

    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }

    int j = 0;
    bool isIt = false;

    while(j < n){
        if(j < n-1 && v[j].second < v[j+1].first)break;
        if(v[j].second >= m){
            isIt = true;
            break;
        }
        j++;
        //cout << j << "\n";
    }

    if(isIt)cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){ans=max(ans,b[j]);
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol&&k>ans){bol2=false;break;}
	}
	if(bol2&&k<=b[n-1])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];mp[a[i]]=mp[b[i]]=true;
		for(int j=a[i];j<=b[i];j++)
			c[j]++;
	}
	for(int i=1;i<m;i++){
		if(c[i]>1||(c[i]>=1&&!mp[i]))bol=true;
		else {bol=false;break;}
	}
	if(bol&&c[0]&&c[m])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++)
		if(a[i]>b[i-1])bol=false;
	if(b[n-1]!=m)bol=false;
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol,bol1;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	sort(b,b+n);
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++)
		if(a[i]>b[i-1])bol=false;
	if(b[n-1]<m)bol=false;
	if(bol&&bol1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		for(int i=a[i];i<=b[i];i++)s[i]=1;
	}
	for(int i=0;i<=k;i++)
		if(s[i]==0){bol=false;break;}
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		for(int i=a[i];i<=b[i];i++)s[i]=1;
	}
	for(int i=0;i<=k;i++)
		if(s[i]==0){bol=false;break;}
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		for(int j=a[i];j<=b[i];j++)s[j]=1;
	}
	for(int i=0;i<=k;i++)
		if(s[i]==0){bol=false;break;}
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol,bol1;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++)
		if(a[i]>b[i-1])bol=false;
	for(int i=0;i<n;i++)
		if(b[i]>=m)bol1=true;
	if(bol&&bol1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol){bol2=false;break;}
	}
	if(bol2&&k<=b[n-1]&&a[0]==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];mp[a[i]]=mp[b[i]]=true;
		for(int j=a[i];j<=b[i];j++)
			c[j]++;
	}
	if(a[i]==1){if(a[0]==0&&b[0]==m)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
	for(int i=1;i<m;i++){
		if(c[i]>1||(c[i]>=1&&!mp[i]))bol=true;
		else {bol=false;break;}
	}
	if(bol&&c[0]&&c[m])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans,l;
bool bol,bol2;
int s[N];
vector<int>v;
map<int,int>mp;
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];if(i)v.push_back(a[i]);if(i<n-1)v.push_back(b[i]);
		for(int j=a[i];j<=b[i];j++)s[j]++;
	}
	sort(v.begin(),v.end());
	for(int i=1;i<v.size();i++)if(v[i]==v[i-1])v.erase(v.begin()+i);
		for(int i=0;i<v.size();i++)mp[v[i]]=1;
	for(int i=0;i<=k;i++){
		if((s[i]>=1&&!mp[i])||(s[i]>=2&&mp[i]))l++;
		else {bol=false;break;}
	}
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++)
		if(a[i]>b[i-1])bol=false;
	if(b[n-1]<m)bol=false;
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol){bol2=false;break;}
	}
	if(bol2&&k<=b[n-1])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){ans=max(ans,b[j]);
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol&&k>ans){bol2=false;break;}
	}
	if(bol2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol){bol2=false;break;}
	}
	if(bol2&&k<=b[n-1]&&a[0]==0&&b[n-1]==k)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++){
		if(a[i]>b[i-1])bol=false;
	}
	if(b[n-1]!=m)bol=false;
	if(bol)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol,bol1;
int main(){
	cin>>n>>m;bol=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	sort(b,b+n);
	if(a[0]!=0)bol=false;
	for(int i=1;i<n;i++)
		if(a[i]>b[i-1])bol=false;
	if(b[n-1]<m)bol=false;
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];mp[a[i]]=mp[b[i]]=true;
		for(int j=a[i];j<=b[i];j++)
			c[j]++;
	}
	if(n==1){if(a[0]==0&&b[0]==m)cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0;}
	for(int i=1;i<m;i++){
		if(c[i]>1||(c[i]>=1&&!mp[i]))bol=true;
		else {bol=false;break;}
	}
	if(bol&&c[0]&&c[m])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];s[a[i]]++;s[b[i]]++;
		for(int j=a[i]+1;j<b[i];j++)s[j]=2;
	}
	for(int i=1;i<k;i++)
		if(s[i]==0||s[i]==1){bol=false;break;}
	if(bol&&s[0]>=1&&s[k]>=1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];s[a[i]]=s[b[i]]=1;
		for(int j=a[i]+1;j<b[i];j++)s[j]=2;
	}
	for(int i=0;i<=k;i++)
		if(s[i]==0||s[i]==1){bol=false;break;}
	if(bol)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

long long n,k,a[N],b[N],ans;
bool bol,bol2;
string s[N];
int main(){
	cin>>n>>k;bol2=true;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){bol=false;
		for(int j=0;j<i;j++){
			if(a[i]<=b[j]){bol=true;break;}
		}
		if(!bol&&k<=b[i]){bol2=false;break;}
	}
	if(bol2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =10000;

int n,k,a[N],b[N],ans;
bool bol,bol2;
int s[N];
int main(){
	cin>>n>>k;bol=true;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];s[a[i]]++;s[b[i]]++;
		for(int j=a[i]+1;j<b[i];j++)s[j]=2;
	}
	for(int i=1;i<k;i++)
		if(s[i]==0||s[i]==1){bol=false;break;}
	if(bol&&s[0]==1&&s[k]==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N =100010;

int x,n,m,a[N],b[N],c[N];
map<int,bool>mp;
bool bol;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(i)if(a[i]==a[i-1]){b[i-1]=max(b[i],b[i-1]);i--;n--;continue;}
		mp[a[i]]=mp[b[i]]=true;
		for(int j=a[i];j<=b[i];j++)
			c[j]++;
	}
	if(n==1){if(a[0]==0&&b[0]==m)cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0;}
	for(int i=1;i<m;i++){
		if(c[i]>1||(c[i]>=1&&!mp[i]))bol=true;
		else {bol=false;break;}
	}
	if(bol&&c[0]&&c[m])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
    int maxi = 0 ;
    pair <int,int>arr[n+5];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
        maxi = max(arr[i].first+arr[i].second , maxi);
    }
        if(maxi >= m){
            bool found = true;
            for(int i = 1 ; i < n ; i++){
                if(arr[i].first > arr[i-1].second){
                    found = false ;
                    break;
                }
            }
            if(found == true){
                cout << "YES" << endl;
            }
            else {
                cout << "NO" << endl;
            }
        }
        else {
            cout << "NO" << endl;
        }
    return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
bool vis[101];
int main(){
    int n,m;
    cin>>n>>m;
    vis[0]=1;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(vis[a]){
            for(int i=a;i<=b;i++){
                vis[i]=1;
            }
        }
    }
    if(vis[m]){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

}
*/


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
    int maxi = 0 ;
    pair<int , int> arr[n+5];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
        maxi = max(maxi,arr[i].second);
    }
    sort(arr,arr+n);
    bool may = true;
    for(int i = 1 ; i < n ; i++){
        if(arr[i].first > arr[i-1].second){
            may = false;
            break;
        }
    }
    if(may == true && maxi >= m){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
    int maxi = 0 ;
    pair <int,int>arr[n+5];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
        maxi = max(arr[i].first+arr[i].second , maxi);
    }
    if(arr[0].first !=0){
        cout << "NO" << endl;
    }
    else {
        if(maxi >= m){
            bool found = true;
            for(int i = 1 ; i < n ; i++){
                if(arr[i].first > arr[i-1].second){
                    found = false ;
                    break;
                }
            }
            if(found == true){
                cout << "YES" << endl;
            }
            else {
                cout << "NO" << endl;
            }
        }
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
bool vis[101];
int main(){
    int n,m;
    cin>>n>>m;
    vis[0]=1;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(vis[a]){
            for(int i=a;i<=b;i++){
                vis[i]=1;
            }
        }
    }
    if(vis[m]){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
    int maxi = 0 ;
    pair <int,int>arr[n+5];
    bool okay = false;
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
        if(arr[i].first == m || arr[i].second == m)
            okay = true;
    }
        if(okay){
            bool found = true;
            for(int i = 1 ; i < n ; i++){
                if(arr[i].first > arr[i-1].second){
                    found = false ;
                    break;
                }
            }
            if(found == true){
                cout << "YES" << endl;
            }
            else {
                cout << "NO" << endl;
            }
        }
        else {
            cout << "NO" << endl;
        }
    return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
bool vis[101];
int main(){
    int n,m;
    cin>>n>>m;
    vis[0]=1;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(vis[a]){
            for(int i=a;i<=b;i++){
                vis[i]=1;
            }
        }
    }
    if(vis[m]){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

}
*/


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
    int maxi = 0 ;
    pair <int,int>arr[n+5];
    bool okay = false;
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
        if(arr[i].first == m || arr[i].second == m)
            okay = true;
    }
    if(arr[0].first !=0){
        cout << "NO" << endl;
    }
    else {
        if(okay){
            bool found = true;
            for(int i = 1 ; i < n ; i++){
                if(arr[i].first > arr[i-1].second){
                    found = false ;
                    break;
                }
            }
            if(found == true){
                cout << "YES" << endl;
            }
            else {
                cout << "NO" << endl;
            }
        }
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
    }//range = i;

    if(ara[0]==0 && ara2[0]==0){
        ok = 0;
    }

    else{
    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

    }
    }

    if(ok == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok=1, findd;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
        if(ara[i] == m){
            findd = 1;
        }
    }//range = i;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

}

    if(ok == 1 && findd == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok=1, findd=0;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
        if(ara2[i] == m || ara[i] == m){
            findd = 1;
        }
    }

    if(n==1){
        findd = 0;
    }       //range = i;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

}

    if(ok == 1 && findd == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok=1, findd=0;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
        if(ara[i] == m){
            findd = 1;
        }
    }//range = i;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

}

    if(ok == 1 && findd == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok=1, findd=0;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
        if(ara2[i] == m || ara[i] == m){
            findd = 1;
        }
    }//range = i;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

}

    if(ok == 1 && findd == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,nn=0,range;
    int a,b,c,d, pos,neg,ok=1, finddd=0;
    int ara[200], ara2[200];

    scanf("%d %d", &n, &m);

    for(int i=0; i<n; i++){
        scanf("%d %d", &ara[i], &ara2[i]);
        if(ara2[i] == m || ara[i] == m){
            finddd = 1;
        }
    }

    if(n==1 && ara[0] == 1){
        finddd = 0;
    }       //range = i;

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(ara[i]<=ara2[j]){
                pos = 1;
            }

        }

        if(pos == 1){
            ok = 1;
        }
        else{
            ok = 0;
            break;
        }
        pos = 0;
        neg = 0;

}

    if(ok == 1 && finddd == 1){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;

}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      if (a[i + 1] > b[i]) {ok=false;break;}
    }
    if (ok) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    if (n == 1) {
      if (b[0] == m) cout << "YES\n"; else cout << "NO\n";
    } else {
    int curPos(a[0]), maxDistUntilNow(b[0]);
    int maxDist(b[b.size() - 1]);
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      maxDistUntilNow = max(maxDistUntilNow, b[i]);
      if (a[i + 1] > maxDistUntilNow) {ok=false;}
    }
    maxDistUntilNow = max(maxDistUntilNow, b[b.size() - 1]);
    if (ok && maxDistUntilNow == maxDist) cout << "YES\n";
    else cout << "NO\n";
    }
    return 0;
}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    if (a[0] != 0) cout << "NO\n";
    else {
    if (n == 1) {
      if (b[0] == m) cout << "YES\n"; else cout << "NO\n";
    } else {
    int curPos(a[0]), maxDistUntilNow(b[0]);
    int maxDist(m);
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      maxDistUntilNow = max(maxDistUntilNow, b[i]);
      if (a[i + 1] > maxDistUntilNow) {ok=false;}
    }
    maxDistUntilNow = max(maxDistUntilNow, b[b.size() - 1]);
    if (ok && maxDistUntilNow == maxDist) cout << "YES\n";
    else cout << "NO\n";
    }
    }
    return 0;
}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    int curPos(a[0]), maxDistUntilNow(b[0]);
    int maxDist(b[b.size() - 1]);
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      maxDistUntilNow = max(maxDistUntilNow, b[i]);
      if (a[i + 1] > maxDistUntilNow) {ok=false;}
    }
    maxDistUntilNow = max(maxDistUntilNow, b[b.size() - 1]);
    if (ok && maxDistUntilNow == maxDist) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    if (n == 1) {
      if (b[0] == m) cout << "YES\n"; else cout << "NO\n";
    } else {
    int curPos(a[0]), maxDistUntilNow(b[0]);
    int maxDist(m);
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      maxDistUntilNow = max(maxDistUntilNow, b[i]);
      if (a[i + 1] > maxDistUntilNow) {ok=false;}
    }
    maxDistUntilNow = max(maxDistUntilNow, b[b.size() - 1]);
    if (ok && maxDistUntilNow == maxDist) cout << "YES\n";
    else cout << "NO\n";
    }
    return 0;
}


/*
 * Author: flagrare7
 * Time: 2020-09-24 23:49:45
**/
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <functional>
#include <numeric>
#include <iomanip>
#include <set>
#include <algorithm>
#include <cstdlib>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mod 1000000007
#define endl '\n'
#define f(i,a,b) for(i=a;i<b;i++)
#define MAX(a,b,c)  max(a,max(b,c))
#define MIN(a,b,c)  min(a,min(b,c))
#define PI 3.1415926535897932
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n; cin >> n >> m;
    vector <int> a(n), b(n);
    for (int i = 0;  i < n; i++) {
      cin >> a[i] >> b[i];
    }
    bool ok(true);
    for (int i = 0; i < n - 1; i++) {
      if (a[i + 1] >= m) {ok=true;break;}
      if (a[i + 1] > b[i]) {ok=false;break;}
    }
    if (ok) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=v[i-1].second) && (v[i].second>reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if(v[i].first<=v[i-1].second)
reach=v[i].second;
else
{
f=1;
break;
}
if(reach==m){cout<<"YES"<<endl;
break;
}
}
if(f==1)
cout<<"NO"<<endl;
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=v[i-1].second) && (v[i].second>reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
}
if(reach!=m){
cout<<"NO"<<endl;
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);

if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}
if(v.size()==1 && reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);

if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;

else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);
if(v[0].first!=0)
cout<<"NO"<<endl;

else if(m>v[n-1].second )
cout<<"NO"<<endl;
else if(v.size()==1){
reach = v[0].second;
if( reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>=reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);

if(m>v[n-1].second)
cout<<"NO"<<endl;
else if(v.size()==1){
reach = v[0].second;
if( reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;

else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);

if(m>v[n-1].second)
cout<<"NO"<<endl;
else if(v.size()==1){
reach = v[0].second;
if( reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>=reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;

else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);

if(m>v[n-1].second || v[0].first!=0)
cout<<"NO"<<endl;
else if(v.size()==1){
reach = v[0].second;
if( reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>=reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;

else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);
for(i=80;i<v.size();i++)
cout<<v[i].first<<" "<<v[i].second<<endl;
if(m>v[n-1].second)
cout<<"NO"<<endl;
else if(v.size()==1){
reach = v[0].second;
if( reach==m)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if((v[i].first<=reach) && (v[i].second>=reach)){

reach=v[i].second;

if(reach==m){
cout<<"YES"<<endl;
break;
}
}

}
if(reach!=m){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if(v[i].first<=v[i-1].second){
reach=v[i].second;
if(reach==m)
cout<<"YES"<<endl;
break;
}

}
if(reach!=m){
cout<<"NO"<<endl;
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=0;i<v.size();i++)
{
if(v[i].first<=v[i-1].second)
reach=v[i].second;
else
{
f=1;
break;
}
if(reach==m){cout<<"YES"<<endl;
break;
}
}
if(f==1)
cout<<"NO"<<endl;
}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;

else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}

sort(v.begin(),v.end(),comp);
 if(m>v[n-1].second )
cout<<"NO"<<endl;
else if(v.size()==1){

reach = v[0].second;
if( reach==m && v[0].first==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else {
reach=v[0].second;
if(v[0].first==0)
f=1;
for(i=1;i<v.size();i++)
{
if(v[i].first==0)
f=1;
if((v[i].first<=reach) && (v[i].second>=reach)){

reach=v[i].second;
if(reach==m && f==1)
{
cout<<"YES"<<endl;
break;
}

}

}
if(reach==m && f!=1)
cout<<"YES";

if(reach!=m ){
cout<<"NO"<<endl;
}

}
return 0;

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &p,
              const pair<int,int> &q){
if(p.second<q.second)
return true;
else if(p.second==q.second){
if(p.first<=q.first)
return true;
else
return false;
}
else
return false;
}
int main(){
int n,m,f=0;
cin>>n>>m;
int i,x,y,reach=-1;
vector<pair<int,int>>v;
for(i=1;i<=n;i++)
{
cin>>x>>y;
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end(),comp);
if(m>v[n-1].second)
cout<<"NO"<<endl;
else {
reach=v[0].second;
for(i=1;i<v.size();i++)
{
if(v[i].first<=v[i-1].second){
reach=v[i].second;
if(reach==m)
cout<<"YES"<<endl;
break;
}

}
}
if(reach!=m){
cout<<"NO"<<endl;
}
return 0;

}


/*****************************************
****       Solution by SlavicG        ****
*****************************************/

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define vair <vector<pair<int,int>>
#define vi vector<int>
#define mp make_pair
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI   3.14159265
#define _Yes printf("YES\n");
#define _No printf("NO\n");
#define scanline; scanf(" %[^\n]s\n",s);
#define print3(x,y,z); cout << x << " " << y << " " << z << endl;
const ll MOD = 1000000007;
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n)
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool isPrime(ll n)
{
    if(n<2) return false;
    for(ll x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m;
    for (int i = 0; i <(int)s.length(); i++) {
        m[s[i]]++;
    }
    return m.size();
}
class BST
{
private:

	struct node
	{
		int key;
		node* left;
		node* right;
	};
	node* root;
	void addLeafPrivate(int key,node* Ptr);
public:

	BST();
	node* createLeaf(int key);
	void addLeaf(int key);
};
BST::BST()
{
	root = NULL;
}
	BST::node* BST::createLeaf(int key)
	{
		node* neww = new node;
		neww->key = key;
		neww->left = NULL;
		neww->right = NULL;
		return neww;
	}
	void BST::addLeaf(int key)
	{
		addLeafPrivate(key,root);
	}
	void BST::addLeafPrivate(int key,node* Ptr)
	{
		if(root == NULL)
		{
			root = createLeaf(key);
		}else if(key < Ptr->key)
		{
			if(Ptr->left!=NULL)
			{
				addLeafPrivate(key,Ptr->left);
			}else{
				Ptr->left = createLeaf(key);
			}
		}
		else if(key > Ptr->key)
		{
			if(Ptr->right != NULL)
			{
				addLeafPrivate(key,Ptr->right);
			}else{
				Ptr->right = createLeaf(key);
			}
		}else
		{
			//already been added
		}
	}
void sortStringByLenght(string s[], int n)
{
    for (int i=1 ;i<n; i++)
    {
        string temp = s[i];
        int j = i - 1;
        while (j >= 0 && temp.length() < s[j].length())
        {
            s[j+1] = s[j];
            j--;
        }
        s[j+1] = temp;
    }
}
int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();
    for (int i = 0; i <= N - M; i++) {
        int j;
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;
        if (j == M)
            return true;
    }
    return false;
}
vector<int> primes;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.pb(p);
}
int main()
{
	int m,n,p=0,g=0,pg=0;
	cin >> m >> n;
    int a[m],b[m];
    for(int i = 0; i < m;i++)
    {
        cin >> a[i] >> b[i];
        if(b[i]>=n){
            g++;
		}
    }
    if(g==0 || a[0] !=0){
        cout<<"NO" << endl;
		return 0;
	}
       for(int i=0;i<m-1;i++)
       {
            if(b[i]>b[i+1])
			{
                b[i+1]=b[i];
			}
            if(a[i+1]>b[i])
			{
				p++;
				cout<<"NO" << endl;
				break;
			}
            if(b[i]>=n)
			{
				pg++;
				cout<<"YES" << endl;
				break;
			}
       }
        if(p == 0 && pg == 0)
		{
        cout<<"YES" << endl;;
		}
	return 0;
}


/*****************************************
****       Solution by SlavicG        ****
*****************************************/

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define vair <vector<pair<int,int>>
#define vi vector<int>
#define mp make_pair
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI   3.14159265
#define _Yes printf("YES\n");
#define _No printf("NO\n");
#define scanline; scanf(" %[^\n]s\n",s);
#define print3(x,y,z); cout << x << " " << y << " " << z << endl;
const ll MOD = 1000000007;
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n)
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool isPrime(ll n)
{
    if(n<2) return false;
    for(ll x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m;
    for (int i = 0; i <(int)s.length(); i++) {
        m[s[i]]++;
    }
    return m.size();
}
class BST
{
private:

	struct node
	{
		int key;
		node* left;
		node* right;
	};
	node* root;
	void addLeafPrivate(int key,node* Ptr);
public:

	BST();
	node* createLeaf(int key);
	void addLeaf(int key);
};
BST::BST()
{
	root = NULL;
}
	BST::node* BST::createLeaf(int key)
	{
		node* neww = new node;
		neww->key = key;
		neww->left = NULL;
		neww->right = NULL;
		return neww;
	}
	void BST::addLeaf(int key)
	{
		addLeafPrivate(key,root);
	}
	void BST::addLeafPrivate(int key,node* Ptr)
	{
		if(root == NULL)
		{
			root = createLeaf(key);
		}else if(key < Ptr->key)
		{
			if(Ptr->left!=NULL)
			{
				addLeafPrivate(key,Ptr->left);
			}else{
				Ptr->left = createLeaf(key);
			}
		}
		else if(key > Ptr->key)
		{
			if(Ptr->right != NULL)
			{
				addLeafPrivate(key,Ptr->right);
			}else{
				Ptr->right = createLeaf(key);
			}
		}else
		{
			//already been added
		}
	}
void sortStringByLenght(string s[], int n)
{
    for (int i=1 ;i<n; i++)
    {
        string temp = s[i];
        int j = i - 1;
        while (j >= 0 && temp.length() < s[j].length())
        {
            s[j+1] = s[j];
            j--;
        }
        s[j+1] = temp;
    }
}
int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();
    for (int i = 0; i <= N - M; i++) {
        int j;
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;
        if (j == M)
            return true;
    }
    return false;
}
vector<int> primes;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.pb(p);
}
int main()
{
	int n,m;
	cin >> n >> m;
	int a,b;
	vector<pair<int,int>> v;
	for(int i = 0;i<n;i++)
	{
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	sort(all(v));
	if(v[0].first!=0)
	{
		cout << "NO" << endl;
	}
	for(int i = 1;i<n;i++)
	{
		if(v[i].first <= v[i-1].second)
		{
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}
	if(v[n-1].second >= m)
	{
		cout << "YES" << endl;
		return 0;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


/*****************************************
****       Solution by SlavicG        ****
*****************************************/

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define vair <vector<pair<int,int>>
#define vi vector<int>
#define mp make_pair
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI   3.14159265
#define _Yes printf("YES\n");
#define _No printf("NO\n");
#define scanline; scanf(" %[^\n]s\n",s);
#define print3(x,y,z); cout << x << " " << y << " " << z << endl;
const ll MOD = 1000000007;
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n)
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool isPrime(ll n)
{
    if(n<2) return false;
    for(ll x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m;
    for (int i = 0; i <(int)s.length(); i++) {
        m[s[i]]++;
    }
    return m.size();
}
class BST
{
private:

	struct node
	{
		int key;
		node* left;
		node* right;
	};
	node* root;
	void addLeafPrivate(int key,node* Ptr);
public:

	BST();
	node* createLeaf(int key);
	void addLeaf(int key);
};
BST::BST()
{
	root = NULL;
}
	BST::node* BST::createLeaf(int key)
	{
		node* neww = new node;
		neww->key = key;
		neww->left = NULL;
		neww->right = NULL;
		return neww;
	}
	void BST::addLeaf(int key)
	{
		addLeafPrivate(key,root);
	}
	void BST::addLeafPrivate(int key,node* Ptr)
	{
		if(root == NULL)
		{
			root = createLeaf(key);
		}else if(key < Ptr->key)
		{
			if(Ptr->left!=NULL)
			{
				addLeafPrivate(key,Ptr->left);
			}else{
				Ptr->left = createLeaf(key);
			}
		}
		else if(key > Ptr->key)
		{
			if(Ptr->right != NULL)
			{
				addLeafPrivate(key,Ptr->right);
			}else{
				Ptr->right = createLeaf(key);
			}
		}else
		{
			//already been added
		}
	}
void sortStringByLenght(string s[], int n)
{
    for (int i=1 ;i<n; i++)
    {
        string temp = s[i];
        int j = i - 1;
        while (j >= 0 && temp.length() < s[j].length())
        {
            s[j+1] = s[j];
            j--;
        }
        s[j+1] = temp;
    }
}
int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();
    for (int i = 0; i <= N - M; i++) {
        int j;
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;
        if (j == M)
            return true;
    }
    return false;
}
vector<int> primes;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.pb(p);
}
int main()
{
	int n,m;
	cin >> n >> m;
	int a,b;
	vector<pair<int,int>> v;
	for(int i = 0;i<n;i++)
	{
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	if(v[0].first!=0)
	{
		cout << "NO" << endl;
	}
	for(int i = 1;i<n;i++)
	{
		if(v[i].first <= v[i-1].second)
		{
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}
	if(v[n-1].second >= m)
	{
		cout << "YES" << endl;
		return 0;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


/*****************************************
****       Solution by SlavicG        ****
*****************************************/

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define vair <vector<pair<int,int>>
#define vi vector<int>
#define mp make_pair
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI   3.14159265
#define _Yes printf("YES\n");
#define _No printf("NO\n");
#define scanline; scanf(" %[^\n]s\n",s);
#define print3(x,y,z); cout << x << " " << y << " " << z << endl;
const ll MOD = 1000000007;
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n)
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool isPrime(ll n)
{
    if(n<2) return false;
    for(ll x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m;
    for (int i = 0; i <(int)s.length(); i++) {
        m[s[i]]++;
    }
    return m.size();
}
class BST
{
private:

	struct node
	{
		int key;
		node* left;
		node* right;
	};
	node* root;
	void addLeafPrivate(int key,node* Ptr);
public:

	BST();
	node* createLeaf(int key);
	void addLeaf(int key);
};
BST::BST()
{
	root = NULL;
}
	BST::node* BST::createLeaf(int key)
	{
		node* neww = new node;
		neww->key = key;
		neww->left = NULL;
		neww->right = NULL;
		return neww;
	}
	void BST::addLeaf(int key)
	{
		addLeafPrivate(key,root);
	}
	void BST::addLeafPrivate(int key,node* Ptr)
	{
		if(root == NULL)
		{
			root = createLeaf(key);
		}else if(key < Ptr->key)
		{
			if(Ptr->left!=NULL)
			{
				addLeafPrivate(key,Ptr->left);
			}else{
				Ptr->left = createLeaf(key);
			}
		}
		else if(key > Ptr->key)
		{
			if(Ptr->right != NULL)
			{
				addLeafPrivate(key,Ptr->right);
			}else{
				Ptr->right = createLeaf(key);
			}
		}else
		{
			//already been added
		}
	}
void sortStringByLenght(string s[], int n)
{
    for (int i=1 ;i<n; i++)
    {
        string temp = s[i];
        int j = i - 1;
        while (j >= 0 && temp.length() < s[j].length())
        {
            s[j+1] = s[j];
            j--;
        }
        s[j+1] = temp;
    }
}
int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();
    for (int i = 0; i <= N - M; i++) {
        int j;
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;
        if (j == M)
            return true;
    }
    return false;
}
vector<int> primes;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.pb(p);
}
int main()
{
	int n,m;
	cin >> n >> m;
	int a,b;
	vector<pair<int,int>> v;
	for(int i = 0;i<n;i++)
	{
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	if(v[0].first!=0)
	{
		cout << "NO" << endl;
	}
	for(int i = 1;i<n;i++)
	{
		if(v[i].first <= v[i-1].second)
		{
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES"  << endl;
	return 0;
}