package A2019;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class 外卖店的优先级 {
static int n;
static int m;
static int time;
static int[] a;
static node[] nod;
static boolean[] b;
static HashMap<Integer,Integer> hs=new HashMap<Integer,Integer>();
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
n=in.nextInt();
m=in.nextInt();
time=in.nextInt();
a=new int[n+1];
nod=new node[m];
b=new boolean[n+1];
for(int i=0;i<m;i++) {
int ts=in.nextInt();
int id=in.nextInt();
node t=new node(ts,id);
nod[i]=t;
}
Arrays.sort(nod,new Comparator<node>(){
@Override
public int compare(node a,node b) {
return a.ts-b.ts;
}
});
for(int i=0;i<m;i++) {
int id=nod[i].id;
int ts=nod[i].ts;
if(hs.get(id)==null) {
a[id]=2;
hs.put(id, ts);
}else {
int pre=hs.get(id);
int d=ts-pre;
if(d==0) a[id]+=2;
else
a[id]=a[id]-d+1+2;
if(a[id]>5) {
b[id]=true;
}else if(b[id]==true&&a[id]<=3) {
b[id]=false;
}
hs.put(id, ts);
}
}
for(Map.Entry<Integer,Integer>entry : hs.entrySet()) {
int id=entry.getKey();
int ts=entry.getValue();
if(ts<time) {
int d=time-ts;
a[id]=a[id]-d;
if(b[id]==true&&a[id]<=3) {
b[id]=false;
}
}
}
int sum=0;
for(int i=1;i<=n;i++) {
if(b[i])
sum++;
}
System.out.println(sum);
}
static class node{
int ts;
int id;
public node(int ts, int id) {
super();
this.ts = ts;
this.id = id;
}
}
}