#include <bits/stdc++.h>
using namespace std;
int mnt[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int summnt[20];
long long getSecond(int m, int d, int h, int min, int sec) {
  return summnt[m - 1] * 24 * 3600ll + d * 24 * 3600 + h * 3600ll + min * 60ll +
         sec;
}
int toInt(string s) {
  int ans = 0;
  for (int i = 0; i < s.length(); i++) ans = ans * 10 + s[i] - '0';
  return ans;
}
long long parse(string &s) {
  s = s.substr(0, 19);
  int m = toInt(s.substr(5, 2));
  int d = toInt(s.substr(8, 2));
  int h = toInt(s.substr(11, 2));
  int min = toInt(s.substr(14, 2));
  int sec = toInt(s.substr(17, 2));
  return getSecond(m, d, h, min, sec);
}
priority_queue<long long> times;
int main() {
  for (int i = 1; i <= 12; i++) summnt[i] = summnt[i - 1] + mnt[i - 1];
  int n, m;
  cin >> n >> m;
  cin.ignore();
  string s;
  while (getline(cin, s)) {
    long long nowtime = parse(s);
    times.push(-nowtime);
    while (!times.empty() && nowtime + times.top() >= n) times.pop();
    if (times.size() >= m) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
