#include <bits/stdc++.h>
using namespace std;
long long s[int(1e5 + 5)], i, m, ans, k, l, j, q, x, n, ma, mi, w, r;
string S, t[int(1e5 + 5)];
vector<int> v;
long long a[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
void pr(int x) {
  for (int i = 0; i < 19; i++) cout << t[x][i];
  cout << endl;
}
int main() {
  cin >> n >> m;
  getline(cin, S);
  while (getline(cin, S)) {
    t[q++] = S;
    for (int i = 0; i < S.size(); i++) s[i] = S[i] - '0';
    w = s[5] * 10 + s[6];
    w = a[w - 1] + s[8] * 10 + s[9];
    w = 24 * w + s[11] * 10 + s[12];
    w = 60 * w + s[14] * 10 + s[15];
    w = 60 * w + s[17] * 10 + s[18];
    v.push_back(w);
  }
  l = 0;
  r = 0;
  x = 0;
  while (l < v.size() && r < v.size()) {
    if (x < n) {
      r++;
      if (r == v.size()) break;
      x += v[r] - v[r - 1];
    } else {
      l++;
      x -= v[l] - v[l - 1];
    }
    if (x < n) {
      if (r - l + 1 >= m) {
        pr(r);
        return 0;
      }
    }
  }
  cout << -1;
}
