#include <bits/stdc++.h>
using namespace std;
char s[5000010], nu;
int month[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
int get(int i) { return (s[i] - '0') * 10 + (s[i + 1] - '0'); }
int cnt, n, m, lg[500010];
int main() {
  scanf("%d%d%c", &n, &m, &nu);
  while (gets(s)) {
    int sec;
    sec = month[get(5) - 1] + get(8);
    sec = sec * 24 + get(11);
    sec = sec * 60 + get(14);
    sec = sec * 60 + get(17);
    lg[cnt++] = sec;
  }
  sort(lg, lg + cnt);
  for (int i = 0, j = 0; j < cnt; j++) {
    if (i < j && lg[j] - lg[i] >= n) i++;
    if (j - i + 1 >= m) {
      int sec = lg[j] % 60;
      lg[j] /= 60;
      int min = lg[j] % 60;
      lg[j] /= 60;
      int hor = lg[j] % 24;
      lg[j] /= 24;
      int k;
      for (k = 0; k < 12; k++)
        if (month[k] >= lg[j]) break;
      int day = lg[j] - month[k - 1];
      int mon = k;
      printf("2012-%02d-%02d %02d:%02d:%02d\n", mon, day, hor, min, sec);
      return 0;
    }
  }
  puts("-1");
}
