#include <bits/stdc++.h>
using namespace std;
const int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[5000500];
int N, a[5000500];
int getTime(char s[]) {
  int m = (s[5] - '0') * 10 + s[6] - '0';
  int d = (s[8] - '0') * 10 + s[9] - '0';
  int h = (s[11] - '0') * 10 + s[12] - '0';
  int mi = (s[14] - '0') * 10 + s[15] - '0';
  int second = (s[17] - '0') * 10 + s[18] - '0';
  for (int i = 1; i <= m - 1; i++) d += month[i];
  return d * 86400 + h * 3600 + mi * 60 + second;
}
void write(int t) {
  int second = t % 60;
  t /= 60;
  int mi = t % 60;
  t /= 60;
  int h = t % 24;
  t /= 24;
  int m, d = t;
  for (int i = 1; i <= 12; i++)
    if (d >= month[i])
      d -= month[i];
    else {
      m = i;
      break;
    }
  cout << "2012-" << m / 10 << m % 10 << '-' << d / 10 << d % 10 << ' ';
  cout << h / 10 << h % 10 << ':' << mi / 10 << mi % 10 << ':' << second / 10
       << second % 10 << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  gets(s);
  while (gets(s)) a[N++] = getTime(s);
  for (int i = m - 1; i <= N - 1; i++)
    if (a[i] - a[i - m + 1] < n) {
      write(a[i]);
      return 0;
    }
  puts("-1");
}
