#include <bits/stdc++.h>
using namespace std;
using pll = pair<int, int>;
#define x first
#define y second
const int N = 1e5 + 10;
int last[N], pr[N];
bool st[N];
pll a[N];
int n, m, t;
int main()
{
cin >> n >> m >> t;
for (int i = 1; i <= m; i++)
{
int ts, id;
cin >> ts >> id;
a[i] = {ts, id};
}
sort(a + 1, a + m + 1);
for (int i = 1; i <= m; i++)
{
int ts = a[i].x, id = a[i].y;
pr[id] -= max(ts - 1, last[id]) - last[id];
if (pr[id] < 0)
pr[id] = 0;
if (pr[id] <= 3)
st[id] = 0;
pr[id] += 2;
if (pr[id] > 5)
st[id] = 1;
last[id] = ts;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
{
pr[i] -= t - last[i];
if (pr[i] <= 3)
st[i] = 0;
cnt += st[i];
}
cout << cnt;
}