#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
vector<int> q;
int mo[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int h, w;
int data(int x, int y) {
  int tmp = 0;
  for (int i = 0; i < x - 1; i++) tmp += mo[i];
  return tmp + y;
}
int cal(int x, int y, int z) { return x * 60 * 60 + y * 60 + z; }
int getpos(string s) {
  int p = data((s[5] - '0') * 10 + s[6] - '0', (s[8] - '0') * 10 + s[9] - '0');
  int res = (p - 1) * 24 * 60 * 60;
  res += cal((s[11] - '0') * 10 + s[12] - '0', (s[14] - '0') * 10 + s[15] - '0',
             (s[17] - '0') * 10 + s[18] - '0');
  return res;
}
int main() {
  cin >> n >> m;
  h = 0;
  getline(cin, s);
  while (getline(cin, s)) {
    int t = getpos(s);
    q.push_back(t);
    while (h < q.size() && t - q[h] >= n) h++;
    if (q.size() - h >= m) {
      for (int i = 0; i <= 18; i++) cout << s[i];
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
