#include <bits/stdc++.h>
using namespace std;
const int day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum[15];
int n, m;
char s[500005];
int a[500005];
int main() {
  for (int i = 2; i <= 12; i++) {
    sum[i] = sum[i - 1] + day[i - 2];
  }
  cin >> n >> m;
  gets(s);
  int cnt = 0;
  bool ok = false;
  while (gets(s)) {
    int t1, t2, t3, d1, d2, d3;
    sscanf(s, "%d-%d-%d %d:%d:%d: %*s", &d1, &d2, &d3, &t1, &t2, &t3);
    a[cnt++] = (sum[d2] + d3) * 3600 * 24 + t1 * 3600 + t2 * 60 + t3;
    if (cnt >= m && a[cnt - 1] - a[cnt - m] < n) {
      ok = true;
      s[19] = 0;
      cout << s << endl;
      break;
    }
  }
  if (!ok) {
    puts("-1");
  }
  cout << endl;
  return 0;
}
