#include <bits/stdc++.h>
using namespace std;
int t[50000000];
int sum(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
  return result;
}
void add(int i, int delta) {
  for (; i < 50000000; i = (i | (i + 1))) t[i] += delta;
}
int main() {
  string s;
  int n, m;
  cin >> n >> m;
  getline(cin, s);
  while (getline(cin, s)) {
    int t = (s[11] - '0') * 10 + s[12] - '0';
    t *= 60;
    t += (s[14] - '0') * 10 + s[15] - '0';
    t *= 60;
    t += (s[17] - '0') * 10 + s[18] - '0';
    int x = (s[5] - '0') * 10 + s[6] - '0';
    x--;
    x *= 31;
    x += (s[8] - '0') * 10 + s[9] - '0';
    t += x * 86400;
    t++;
    add(t, 1);
    x = t - n;
    if (x < 0) x = 0;
    if (sum(t) - sum(x) >= m) {
      for (int i = (0); i < (19); ++i) cout << s[i];
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
