#include <bits/stdc++.h>
using namespace std;
int month[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int cnt[14];
char parse(char* c) { return (c[0] - '0') * 10 + (c[1] - '0'); }
char buffer[5000001];
vector<int> rec;
vector<array<char, 5>> printer;
int main() {
  for (int i = 1; i <= 12; i++) {
    cnt[i + 1] = month[i] + cnt[i];
  }
  int n, m;
  scanf("%d%d\n", &n, &m);
  while (gets(buffer)) {
    char month = parse(buffer + 5);
    char day = parse(buffer + 8);
    char hour = parse(buffer + 11);
    char min = parse(buffer + 14);
    char sec = parse(buffer + 17);
    int S = (cnt[month] + day) * 3600 * 24 + hour * 3600 + min * 60 + sec;
    rec.push_back(S);
    printer.push_back({month, day, hour, min, sec});
  }
  for (int i = 0; i < rec.size(); i++) {
    int index =
        upper_bound(rec.begin(), rec.begin() + i, rec[i] - n) - rec.begin();
    if (i - index + 1 >= m) {
      printf("2012-%02d-%02d %02d:%02d:%02d\n", printer[i][0], printer[i][1],
             printer[i][2], printer[i][3], printer[i][4]);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
