#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
char s[5000105];
int gg(int i) { return s[i] - '0'; }
int mh[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int getM(int m) {
  m--;
  int ans = 0;
  for (int(i) = 0; (i) < (int)(m); (i)++) ans += mh[i];
  return ans;
}
int gett() {
  int s = 0;
  s += gg(18) + 10 * gg(17);
  s += (gg(15) + 10 * gg(14)) * 60;
  s += (gg(12) + 10 * gg(11)) * 3600;
  s += (gg(9) + 10 * gg(8) - 1) * 3600 * 24;
  s += getM((gg(6) + 10 * gg(5))) * 3600 * 24;
  return s;
}
void pp() {
  for (int(i) = 0; (i) < (int)(19); (i)++) printf("%c", s[i]);
  exit(0);
}
int main() {
  scanf("%d%d", &n, &m);
  queue<int> t;
  while (cin.getline(s, 5000105)) {
    int time = gett();
    t.push(time);
    if (t.size() == m) {
      int f = t.front();
      t.pop();
      if (time - f < n) {
        pp();
      }
    }
  }
  puts("-1");
  return 0;
}
