#include <bits/stdc++.h>
using namespace std;
const int days[13] = {-1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int t, m;
char buf[5000006];
int main() {
  cin >> t >> m;
  gets(buf);
  queue<int> events;
  int sum = 0;
  while (gets(buf)) {
    for (int i = 0; buf[i]; i++)
      if (!isdigit(buf[i])) buf[i] = ' ';
    int year, month, day, hour, minute, second;
    sscanf(buf, "%d%d%d%d%d%d", &year, &month, &day, &hour, &minute, &second);
    int time = 0;
    for (int i = 1; i < month; i++) time += days[i];
    time += day - 1;
    time *= 24;
    time += hour;
    time *= 60;
    time += minute;
    time *= 60;
    time += second;
    sum++;
    events.push(time + t);
    while (!events.empty() && events.front() <= time) {
      sum--;
      events.pop();
    }
    if (sum >= m) {
      buf[4] = buf[7] = '-';
      buf[13] = buf[16] = ':';
      buf[19] = '\0';
      printf("%s\n", buf);
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
