#include <bits/stdc++.h>
using namespace std;
int month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int in(string x) {
  stringstream ss;
  ss << x;
  int ret;
  ss >> ret;
  return ret;
}
void solve() {
  vector<int> x;
  int n, m;
  cin >> n >> m;
  string s;
  getline(cin, s);
  int start = 0;
  while (getline(cin, s)) {
    int mnth = in(s.substr(5, 2));
    int day = in(s.substr(8, 2));
    int hh = in(s.substr(11, 2));
    int mm = in(s.substr(14, 2));
    int ss = in(s.substr(17, 2));
    int tot = ss;
    tot += mm * 60;
    tot += (hh * 60 * 60);
    tot += (day * 24 * 60 * 60);
    for (int i = 0; i + 1 < mnth; ++i) {
      tot += (month[i] * 24 * 60 * 60);
    }
    x.push_back(tot);
    while (x.back() - x[start] + 1 > n) {
      start++;
    }
    if (x.size() - start >= m) {
      cout << s.substr(0, 19) << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int T = 1;
  while (T--) {
    solve();
  }
}
