#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 100010;
bool poster[N];
struct Interval{
int l,r;
}intervals[N];
struct point{
int num,id;
}points[N<<1];
struct node{
int l,r,setv;
}tree[N<<2];
bool cmp(const point &a,const point &b){
return a.num < b.num;
}
void build(int id,int l,int r){
tree[id].l = l;
tree[id].r = r;
tree[id].setv = 0;
if(l == r)
return;
int mid = (l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
}
void pushdown(int id){
if(tree[id].setv){
tree[id<<1].setv = tree[id].setv;
tree[id<<1|1].setv = tree[id].setv;
tree[id].setv = 0;
}
}
void update(int id,int l,int r,int val){
if(tree[id].l >= l && tree[id].r <= r){
tree[id].setv = val;
return;
}
pushdown(id);
int mid = (tree[id].l+tree[id].r)>>1;
if(l <= mid)
update(id<<1,l,r,val);
if(mid < r)
update(id<<1|1,l,r,val);
}
void query(int id,int l,int r){
if (tree[id].setv){
poster[tree[id].setv] = true;
return;
}
if(tree[id].l < tree[id].r){
int mid = (tree[id].l + tree[id].r)>>1;
if(l <= mid)
query(id<<1,l,r);
if(mid < r)
query(id<<1|1,l,r);
}
}
int main(){
int n,l,x;
scanf("%d%d",&n,&l);
for(int i = 1; i <= n; i++)
poster[i] = false;
for(int i = 1; i <= 2*n; i++){
scanf("%d",&x);
points[i].id = i;
points[i].num = x;
}
sort(points+1,points+2*n+1,cmp);
int number = -1;
int index = 0;
for(int i = 1; i <= 2*n; i++){
if(points[i].num != number){
number = points[i].num;
index++;
}
if(points[i].id%2)
intervals[(points[i].id+1)/2].l = index;
else
intervals[(points[i].id+1)/2].r = index-1;
}
build(1,1,index-1);
for(int i = 1; i <= n; i++)
update(1,intervals[i].l,intervals[i].r,i);
query(1,1,index-1);
int sum = 0;
for(int i = 1; i <= n; i++){
if(poster[i])
sum++;
}
printf("%d\n",sum);
return 0;
}