#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
long long que[maxn];
int sum[20];
int front, tail;
long long cal(long long month, long long date, long long hour, long long mi,
              long long sec) {
  long long res = (sum[month] + date - 1) * 3600 * 24;
  res += hour * 3600 + mi * 60 + sec;
  return res;
}
void tr(int x) { printf("%d%d", x / 10, x % 10); }
int main() {
  sum[2] = 31;
  sum[3] = 60;
  sum[4] = 91;
  sum[5] = 121;
  sum[6] = 152;
  sum[7] = 182;
  sum[8] = 213;
  sum[9] = 244;
  sum[10] = 274;
  sum[11] = 305;
  sum[12] = 335;
  int n, m;
  scanf("%d%d", &n, &m);
  getchar();
  front = 1, tail = 0;
  string str;
  int month, date, hour, mi, sec;
  while (1) {
    if (scanf("2012-%d-%d", &month, &date) == EOF) break;
    scanf(" %d:%d:%d: ", &hour, &mi, &sec);
    que[++tail] = cal(month, date, hour, mi, sec);
    while (tail >= front && que[tail] - que[front] >= n) front++;
    if (tail - front + 1 >= m) {
      printf("2012-");
      tr(month);
      putchar('-');
      tr(date);
      putchar(' ');
      tr(hour);
      putchar(':');
      tr(mi);
      putchar(':');
      tr(sec);
      putchar('\n');
      return 0;
    }
    getline(cin, str);
  }
  puts("-1");
}
