#include <bits/stdc++.h>
using namespace std;
const int N = 11000, M = 4e7 + 100;
int n, m, st[100][100], a[N];
char s[N], t[N], as[N], at[N];
int day[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
queue<int> q;
inline int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline int calday(char s[]) {
  int m = (s[6] - '0') * 10 + s[7] - '0', d = (s[9] - '0') * 10 + s[10] - '0';
  for (int i = 1; i < m; i++) d += day[i];
  return d * 24 * 60 * 60;
}
inline int calin(char s[]) {
  int h, m, se;
  h = (s[1] - '0') * 10 + s[2] - '0';
  m = (s[4] - '0') * 10 + s[5] - '0';
  se = (s[7] - '0') * 10 + s[8] - '0';
  return h * 60 * 60 + m * 60 + se;
}
inline void endline() {
  char x = getchar();
  while (x != '\n') x = getchar();
}
signed main() {
  n = read();
  m = read();
  int i = 0;
  bool bl = 1;
  while (scanf("%s", s + 1) != EOF) {
    i++;
    a[i] = calday(s);
    scanf("%s", t + 1);
    a[i] += calin(t);
    endline();
    while (!q.empty() && a[i] - q.front() >= n) q.pop();
    q.push(a[i]);
    if ((int)q.size() >= m) {
      printf("%s ", s + 1);
      for (int i = 1; i <= 8; i++) printf("%c", t[i]);
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
}
