#include <bits/stdc++.h>
using namespace std;
char a[1000005];
vector<int> D;
int parse(char *s, char *e) {
  int val = 0;
  while (s != e) val = val * 10 + (*(s++)) - '0';
  return val;
}
void parse() {
  int year = parse(a, a + 4);
  int month = parse(a + 5, a + 7);
  int day = parse(a + 8, a + 10);
  int hour = parse(a + 11, a + 13);
  int minute = parse(a + 14, a + 16);
  int second = parse(a + 17, a + 19);
  D.push_back(year);
  D.push_back(month);
  D.push_back(day);
  D.push_back(hour);
  D.push_back(minute);
  D.push_back(second);
}
int getTime(int year, int mon, int day, int hour, int minute, int second) {
  static int ms[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int days = 0;
  for (int i = 1; i < mon; i++) days += ms[i];
  days += day;
  days *= 86400;
  days += hour * 3600 + minute * 60 + second;
  return days;
}
int compare(int x, int y) {
  int vx = getTime(D[x], D[x + 1], D[x + 2], D[x + 3], D[x + 4], D[x + 5]);
  int vy = getTime(D[y], D[y + 1], D[y + 2], D[y + 3], D[y + 4], D[y + 5]);
  return vy - vx;
}
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  gets(a);
  while (gets(a) != NULL) {
    if (a[0] == '2') parse();
  }
  int fail = 1;
  for (int i = (m - 1) * 6; i < ((int)(D).size()); i += 6) {
    if (compare(i - (m - 1) * 6, i) < n) {
      printf("%04d-%02d-%02d %02d:%02d:%02d\n", D[i], D[i + 1], D[i + 2],
             D[i + 3], D[i + 4], D[i + 5]);
      fail = 0;
      break;
    }
  }
  if (fail) puts("-1");
  return 0;
}
