#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n, m, head;
string s;
int input(string temp) {
  int val;
  stringstream sin;
  sin << temp;
  sin >> val;
  return val;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  getline(cin, s);
  while (getline(cin, s)) {
    int month = input(s.substr(5, 2));
    int day = input(s.substr(8, 2));
    int hour = input(s.substr(11, 2));
    int min = input(s.substr(14, 2));
    int second = input(s.substr(17, 2));
    int sec = second + min * 60 + hour * 3600 + day * 24 * 3600;
    for (int i = 0; i + 1 < month; i++) sec += months[i] * 24 * 3600;
    while (head < (int)v.size() && v[head] + n <= sec) head++;
    v.push_back(sec);
    if ((int)v.size() - head == m) {
      cout << s.substr(0, 19) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
