#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
int Y[maxn], M[maxn], D[maxn], h[maxn], m[maxn], s[maxn];
int a[maxn], na, n, k;
char buf[5001010];
int mh[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum[13];
int main() {
  sum[0] = 0;
  for (int i = 1; i <= 12; i++) sum[i] = sum[i - 1] + mh[i];
  scanf("%d%d", &n, &k);
  na = 0;
  while (scanf("%d-%d-%d %d:%d:%d", &Y[na], &M[na], &D[na], &h[na], &m[na],
               &s[na]) != EOF) {
    gets(buf);
    a[na] = 3600 * 24 * (sum[M[na] - 1] + D[na] - 1) + 3600 * h[na] +
            60 * m[na] + s[na];
    na++;
  }
  int i;
  for (i = 0; i < na; i++) {
    int t = a[i] - n;
    int ix = upper_bound(a, a + na, t) - a;
    if (i - ix + 1 >= k) {
      printf("%d-%02d-%02d %02d:%02d:%02d\n", Y[i], M[i], D[i], h[i], m[i],
             s[i]);
      break;
    }
  }
  if (i == na) printf("-1\n");
  return 0;
}
