#include <bits/stdc++.h>
using namespace std;
char s[10000000];
int month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool solve() {
  int n, m;
  if (scanf("%d%d", &n, &m) == EOF) return false;
  bool fnd = false;
  deque<int> dd;
  gets(s);
  while (!feof(stdin)) {
    int y, M, d, h, mm, ss;
    if (scanf("%d\-%d\-%d%d\:%d\:%d\:", &y, &M, &d, &h, &mm, &ss) == EOF) break;
    gets(s);
    int m2 = M;
    if (!fnd) {
      int ans = ss + mm * 60 + h * 60 * 60 + (d - 1) * 24 * 60 * 60;
      while (M > 1) {
        M--;
        ans += month[M - 1] * 24 * 60 * 60;
      }
      dd.push_back(ans);
      while (!dd.empty() && ans - dd.front() + 1 > n) dd.pop_front();
      if (dd.size() >= m) {
        printf("%d-%02d-%02d %02d:%02d:%02d", y, m2, d, h, mm, ss);
        fnd = true;
      }
    }
  }
  if (!fnd) {
    printf("-1");
  }
  return true;
}
int main() {
  solve();
  return 0;
}
