#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
string s;
int t;
} a[N];
int n, k;
queue<int> q;
map<string, int> mpTime, inQueue;
int main(){
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].s;
int h, m; char ch;
cin >> h >> ch >> m;
a[i].t = h * 60 + m;
}
sort(a + 1, a + n + 1, [](node x, node y) {
return x.t < y.t;
});
int ans = 0;
for (int i = 1; i <= n; i++) {
int nowTime = a[i].t;
while (q.size() && mpTime[a[q.front()].s] + k < nowTime) {
mpTime[a[q.front()].s] = -k - 1;
inQueue[a[q.front()].s] = 0;
q.pop();
}
if (!inQueue[a[i].s]) {
q.push(i);
inQueue[a[i].s] = 1;
}
mpTime[a[i].s] = nowTime;
ans = max(ans, int(q.size()));
}
cout << ans << '\n';
return 0;
}