#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<fstream>

#define A '.'
#define S 'S'
#define G 'G'
#define D '#'

using namespace std;

int N,T;
void getInputs(vector< vector<int> > &maze){

    cin >> N >> T;
    cin.ignore();
    
    for(int i=0;i<N;i++){
        int a,b;
        vector<int> row;
        cin >> a >> b;
        row.push_back(a);
        row.push_back(b);
        maze.push_back(row);
    }

}

int main(){

    vector< vector<int> > cow;

    getInputs(cow);

    vector< pair<int,int> > pea(N);

    int ans = 0;
    int start = 1;
    int end = 1;

    
    for(int i=0;i<N;i++){
        pea[i] = make_pair(cow[i][0],cow[i][1]);
    }

    sort(pea.begin(),pea.end());

    for(int i=N-1;i>=0;i--){
        cout << pea[i].second << "," << pea[i].first << endl;
    }

    end = T;
    start = T;

    for(int i=N-1;i>=0;i--){

        if(pea[i].second >= end ){
            end = pea[i].first;
            if(end == 1){
                break;
            }
        }
    }

    //cout << "end=" << end << endl;

    if(end > 1){
        cout << -1 << endl;
        return 0;
    }

    
    end = 1;


    for(int i=0;i<N;i++){

        if(t >= pea[i].first){
            if(t < pea[i].second){
                t = pea[i].second;
            }
        }
        
    }

    for(int i = 0;i<N;i++){
        if(start >= pea[i].first && end < pea[i].second){
            ans ++;
            start = pea[i].first;
            end = pea[i].second;
        }
    }

    cout << ans << endl;

    return 0;
}