#include <bits/stdc++.h>
using namespace std;
int days[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int to_sec(int mo, int d, int h, int mn, int s) {
  int pdays = 0;
  for (int i = 0; i < mo - 1; i++) pdays += days[i];
  return pdays * 60 * 60 * 24 + (d - 1) * 60 * 60 * 24 + h * 60 * 60 + mn * 60 +
         s;
}
int main() {
  int n, m;
  cin >> n >> m;
  cin.ignore();
  string line;
  vector<pair<int, string> > v;
  while (getline(cin, line)) {
    for (int i = 0; i < line.size(); i++)
      if (line[i] == '-' || line[i] == ':') line[i] = ' ';
    istringstream sin(line);
    int y, mon, d, h, mn, s;
    sin >> y >> mon >> d >> h >> mn >> s;
    v.push_back(make_pair(to_sec(mon, d, h, mn, s), line));
  }
  int i = 0;
  int j = 0;
  int ans = -1;
  while (j < v.size()) {
    if (v[j].first - v[i].first + 1 <= n && j - i + 1 >= m) {
      ans = j;
      break;
    }
    j++;
    while (i < j && v[j].first - v[i].first > n) i++;
  }
  if (ans == -1)
    cout << -1 << endl;
  else {
    v[ans].second[4] = '-';
    v[ans].second[7] = '-';
    v[ans].second[13] = ':';
    v[ans].second[16] = ':';
    cout << v[ans].second.substr(0, 19) << endl;
  }
  return 0;
}
