#include <bits/stdc++.h>
using namespace std;
char str[5000050];
const int MONTH[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
queue<int> q;
int stol(int begin, int end) {
  int ans = 0;
  for (int i = begin; i <= end; i++) ans += str[i] - '0', ans *= 10;
  return ans / 10;
}
int main(void) {
  int n, m, cnt = 0;
  cin >> n >> m;
  getchar();
  while (gets(str)) {
    int month = stol(5, 6), day = stol(8, 9), hour = stol(11, 12),
        min = stol(14, 15), sec = stol(17, 18), time = 0;
    for (int i = 1; i < month; ++i) time += MONTH[i];
    time += day;
    time *= 24;
    time += hour;
    time *= 60;
    time += min;
    time *= 60;
    time += sec;
    cnt++;
    q.push(time + n);
    while (!q.empty() && q.front() <= time) {
      cnt--;
      q.pop();
    }
    if (cnt >= m) {
      printf("2012-%02d-%02d %02d:%02d:%02d", month, day, hour, min, sec, time);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
