#include <bits/stdc++.h>
using namespace std;
char str[5000005];
int a[5000005],
    days[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
int main() {
  int n, m, i, j, mon, dat, hou, minu, sec, *p;
  scanf("%d%d", &n, &m);
  getchar();
  for (i = 0; gets(str); ++i) {
    sscanf(str, "2012-%d-%d %d:%d:%d", &mon, &dat, &hou, &minu, &sec);
    a[i] = (days[mon] + dat) * 86400 + hou * 3600 + minu * 60 + sec;
    if (i > m - 2) {
      p = lower_bound(a, a + i, a[i] - n + 1);
      if (i - (p - a) + 1 >= m) {
        str[19] = '\0';
        printf("%s", str);
        return 0;
      }
    }
  }
  printf("-1");
  return 0;
}
