#include <bits/stdc++.h>
using namespace std;
const int dx[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ch(char xxx) { return xxx - '0'; }
int sec(string s) {
  int mon = ch(s[5]) * 10 + ch(s[6]);
  int das = ch(s[8]) * 10 + ch(s[9]);
  for (int i = 0; i < mon - 1; i++) das += dx[i];
  int h = ch(s[11]) * 10 + ch(s[12]);
  int m = ch(s[14]) * 10 + ch(s[15]);
  int sc = ch(s[17]) * 10 + ch(s[18]);
  return das * 86400 + h * 3600 + m * 60 + sc;
}
string s[1000110];
int n, m;
int nlog, nlst;
int a[1000110];
bool has;
int main() {
  scanf("%d%d", &n, &m);
  getline(cin, s[nlog]);
  while (!has) {
    getline(cin, s[nlog]);
    if (s[nlog].size() < 5) break;
    a[nlog] = sec(s[nlog]);
    while (a[nlst] <= a[nlog] - n) nlst++;
    if (nlog - nlst + 1 >= m) {
      cout << s[nlog].substr(0, 19);
      has = true;
    }
    nlog++;
  }
  if (!has) puts("-1");
  return 0;
}
