#include <bits/stdc++.h>
using namespace std;
char buf[5000010], ch;
int a[5000010];
int dc[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
int sd = 24 * 60 * 60;
int main() {
  int n, m, top = 1;
  int YY, MM, DD, hh, mm, ss;
  scanf("%d%d", &n, &m);
  getchar();
  a[0] = 0xc0c0c0c0;
  while (gets(buf)) {
    sscanf(buf, "%d%c%d%c%d%c%d%c%d%c%d", &YY, &ch, &MM, &ch, &DD, &ch, &hh,
           &ch, &mm, &ch, &ss);
    int t = (dc[MM] + DD - 1) * sd + hh * 60 * 60 + mm * 60 + ss;
    a[top++] = t;
    t -= n - 1;
    int l = 0, r = top - 1;
    while (l < r - 1) {
      int mid = l + r >> 1;
      if (a[mid] < t)
        l = mid;
      else
        r = mid;
    }
    if (top - r >= m) {
      buf[19] = 0;
      printf("%s\n", buf);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
