#include <bits/stdc++.h>
using namespace std;
char s[5000005];
int n, m, h0, m0, d0, M0, s0;
int cur = 0;
int mas[500005], sz = 0;
int mnt[12] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
int tosec(int sec, int m, int h, int d, int M) {
  int ss = sec;
  ss += 60 * m;
  ss += 60 * 60 * h;
  for (int i = 0; i < M; ++i) d += mnt[i];
  ss += (d - 1) * 24 * 60 * 60;
  return ss;
}
int main() {
  scanf("%d%d", &n, &m);
  gets(s);
  gets(s);
  sscanf(s, "2012-%d-%d %d:%d:%d", &M0, &d0, &h0, &m0, &s0);
  int ss = tosec(s0, m0, h0, d0, M0);
  mas[sz++] = ss;
  while (1) {
    if (!gets(s)) {
      printf("-1\n");
      return 0;
    }
    sscanf(s, "2012-%d-%d %d:%d:%d", &M0, &d0, &h0, &m0, &s0);
    mas[sz] = tosec(s0, m0, h0, d0, M0);
    for (; mas[sz] - mas[cur] >= n; ++cur)
      ;
    if (sz - cur + 1 >= m) {
      printf("2012-%02d-%02d %02d:%02d:%02d\n", M0, d0, h0, m0, s0);
      return 0;
    }
    sz++;
  }
  return 0;
}
