#include <bits/stdc++.h>
using namespace std;
struct date {
  int mon, dat, hou, minu, sec;
};
char str[5000005];
vector<int> t;
vector<date> ans;
int days[] = {0, 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool input(char s[]) {
  char c;
  int i;
  for (i = 0, c = getchar(); c != EOF && c != '\n'; c = getchar()) s[i++] = c;
  s[i] = '\0';
  if (c == EOF || i == 0) return false;
  return true;
}
int main() {
  int i, mon, dat, hou, minu, sec, n, m, head, tail, sum;
  for (i = 1; i <= 12; ++i) days[i] += days[i - 1];
  scanf("%d %d", &n, &m);
  getchar();
  while (input(str)) {
    sscanf(str + 5, "%d", &mon);
    sscanf(str + 8, "%d", &dat);
    sscanf(str + 11, "%d", &hou);
    sscanf(str + 14, "%d", &minu);
    sscanf(str + 17, "%d", &sec);
    sum = sec + minu * 60 + hou * 3600 + dat * 86400 + days[mon] * 86400;
    t.push_back(sum);
    ans.push_back((date){mon, dat, hou, minu, sec});
  }
  tail = 0;
  for (head = 0; head < t.size(); ++head) {
    while (t[head] - t[tail] >= n) tail++;
    if (head - tail + 1 >= m) break;
  }
  if (head >= t.size())
    puts("-1");
  else
    printf("2012-%02d-%02d %02d:%02d:%02d", ans[head].mon, ans[head].dat,
           ans[head].hou, ans[head].minu, ans[head].sec);
  return 0;
}
