#include <bits/stdc++.h>
using namespace std;
const int months[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int hourSec = 3600;
const int minutesSec = 60;
const int daySec = 3600 * 24;
int N, M;
char buffer[5000010];
vector<int> A;
int f(int m, int d) {
  int i, ret = 0;
  for (i = 1; i < m; i++) ret += daySec * months[i - 1];
  ret += (d - 1) * daySec;
  return ret;
}
string decod(int sec) {
  int mm, dd, hh, minutes, i, r, aux = 0;
  for (aux = 0, i = 1, r = 0; i <= 12; i++) {
    r += months[i - 1] * daySec;
    if (r > sec) break;
    aux += months[i - 1] * daySec;
  }
  mm = i;
  sec -= aux;
  for (aux = 0, i = 1, r = 0; i <= 32; i++) {
    r += daySec;
    if (r > sec) break;
    aux += daySec;
  }
  dd = i;
  sec -= aux;
  for (aux = 0, i = 0, r = 0; i <= 24; i++) {
    r += hourSec;
    if (r > sec) break;
    aux += hourSec;
  }
  hh = i;
  sec -= aux;
  for (aux = 0, i = 0, r = 0; i <= 60; i++) {
    r += minutesSec;
    if (r > sec) break;
    aux += minutesSec;
  }
  minutes = i;
  sec -= aux;
  char buf[128];
  sprintf(buf, "2012-%.2d-%.2d %.2d:%.2d:%.2d", mm, dd, hh, minutes, sec);
  return (string)buf;
}
int main(void) {
  int x, y, dd, mm, hh, minutes, sec;
  scanf("%d %d\n", &N, &M);
  while (scanf("%d-%d-%d %d:%d:%d:", &y, &mm, &dd, &hh, &minutes, &sec) == 6) {
    gets(buffer);
    int n = f(mm, dd) + hh * hourSec + minutes * minutesSec + sec;
    A.push_back(n);
  }
  sort(A.begin(), A.end());
  int i, p = 0;
  for (i = 0; i < A.size(); i++) {
    while (A[i] - A[p] >= N) p++;
    if (i - p + 1 >= M) {
      cout << decod(A[i]);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
