#include <bits/stdc++.h>
using namespace std;
queue<int> que;
int Month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30};
int main() {
  int n, mm;
  string str;
  getline(cin, str);
  stringstream sss(str);
  sss >> n >> mm;
  while (getline(cin, str)) {
    stringstream ss(str);
    char temp;
    int M, D, h, m, s;
    ss >> M >> temp >> M >> temp >> D >> h >> temp >> m >> temp >> s;
    int d = 0;
    for (int i = 1; i < M; i++) d += Month[i];
    d += D - 1;
    d *= 60 * 60 * 24;
    d += h * 60 * 60;
    d += m * 60;
    d += s;
    while (!que.empty() && que.front() <= d - n) {
      que.pop();
    }
    que.push(d);
    if (que.size() >= mm) {
      printf("2012-%02d-%02d %02d:%02d:%02d\n", M, D, h, m, s);
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
