#include <bits/stdc++.h>
using namespace std;
void solve() {
  static const int maxn = 100001;
  int day[20] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int mo[maxn], d[maxn], h[maxn], m[maxn], s[maxn];
  int N, M, a[maxn], k = 0, year;
  scanf("%d%d", &N, &M);
  while (scanf("%d-%d-%d %d:%d:%d", &year, &mo[k], &d[k], &h[k], &m[k],
               &s[k]) != EOF) {
    a[k] = s[k] + m[k] * 60 + h[k] * 60 * 60;
    int days = d[k] - 1;
    for (int i = 1; i < mo[k]; i++) days += day[i];
    a[k++] += days * 60 * 60 * 24;
    char ch;
    while ((ch = getchar()) != '\n')
      ;
  }
  bool flag = false;
  for (int i = M - 1; i < k; i++) {
    if (a[i] - a[i - M + 1] + 1 <= N) {
      flag = true;
      printf("2012-");
      if (mo[i] < 10)
        printf("0%d-", mo[i]);
      else
        printf("%d-", mo[i]);
      if (d[i] < 10)
        printf("0%d ", d[i]);
      else
        printf("%d ", d[i]);
      if (h[i] < 10)
        printf("0%d:", h[i]);
      else
        printf("%d:", h[i]);
      if (m[i] < 10)
        printf("0%d:", m[i]);
      else
        printf("%d:", m[i]);
      if (s[i] < 10)
        printf("0%d\n", s[i]);
      else
        printf("%d\n", s[i]);
      break;
    }
  }
  if (!flag) printf("-1\n");
}
int main() {
  solve();
  return 0;
}
