#include <bits/stdc++.h>
using namespace std;
unsigned long long f(char c) { return c - '0'; }
int mon[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
unsigned long long getSec(string s) {
  unsigned long long mul = 1;
  unsigned long long res = f(s[17]) * 10 + f(s[18]);
  mul = 60;
  res += mul * (f(s[14]) * 10 + f(s[15]));
  mul *= 60;
  res += mul * (f(s[11]) * 10 + f(s[12]));
  mul *= 24;
  res += mul * (f(s[8]) * 10 + f(s[9]));
  int mn = f(s[5]) * 10 + f(s[6]);
  int i;
  for (i = 0; i < mn - 1; ++i) res += mon[i] * mul;
  return res;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char c;
  scanf("%c", &c);
  string s;
  queue<unsigned long long> q;
  int i;
  while (1) {
    s = "";
    if (scanf("%c", &c) != 1) break;
    s += c;
    for (i = 0; i < 18; ++i) {
      scanf("%c", &c);
      s += c;
    }
    while (c != '\n') scanf("%c", &c);
    unsigned long long t = getSec(s);
    q.push(t);
    while (t - q.front() >= n) q.pop();
    if (q.size() >= m) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
