#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector< pair<int, int> > detektori, detektori_stari;
int n,m;

bool cmp( const pair<int, int> &a, const pair <int, int> &b){
    return( a.second < b.second);
}

int main(){
    int n,m, sol = 0;
    scanf("%d %d",&n,&m);
    for(int x = 0;x<n;++x){
        pair<int , int > temp;
        scanf("%d %d", &temp.first, &temp.second);
        detektori.push_back(temp);
        detektori_stari.push_back(temp);
    }
    int t = 0;
    sort( detektori.begin(), detektori.end(), cmp );
    sort( detektori_stari.begin(), detektori_stari.end());
    for(int x = 0; x < (int) detektori.size(); ++x){
        if( x < (int)detektori.size() - 1  && detektori[x].second == detektori[x+1].second ) continue;
        int grupa = 0;bool bleh = false;
        for(int y = 0;y<n;++y){
            if( bleh == false && detektori_stari[y].second > detektori[x].second - 1){
                grupa++;
                bleh = true;
            }
            if( detektori_stari[y].second <= detektori[x].second - 1 ){
                bleh = false;
            }
        }
        sol += (detektori[x].second - t) * grupa;
        t = detektori[x].second;
    }
    
    printf("%d\n",sol);
    return 0;
}
