#include <bits/stdc++.h>
using namespace std;
const int maxn = 500008;
int n, m, cnt;
int day[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int get(int x) {
  int ret = 0;
  for (int i = 0; i < x; ++i) ret += day[i];
  return ret;
}
struct Node {
  int year, month, date;
  int hour, minute, second;
  int dis;
  Node() {}
  Node(int Y, int M, int D, int H, int Mi, int S) {
    year = Y, month = M, date = D;
    hour = H, minute = Mi, second = S;
    dis = second + minute * 60 + hour * 3600;
    if (date - 1 == 0) {
      dis += day[month - 1] * 24 * 3600 + get(month - 1) * 24 * 3600;
    } else
      dis += (date - 1) * 24 * 3600 + get(month) * 24 * 3600;
  };
} node[maxn];
int main() {
  cin >> n >> m;
  string str;
  cnt = 0;
  while (cin >> str) {
    int y = 2012, m = (str[5] - '0') * 10 + str[6] - '0',
        d = (str[8] - '0') * 10 + str[9] - '0';
    cin >> str;
    int h = (str[0] - '0') * 10 + str[1] - '0',
        mi = (str[3] - '0') * 10 + str[4] - '0',
        s = (str[6] - '0') * 10 + str[7] - '0';
    node[++cnt] = Node(y, m, d, h, mi, s);
    getline(cin, str, '\n');
  }
  bool ff = 0;
  int i;
  for (i = m; i <= cnt; ++i) {
    if (node[i].dis - node[i - m + 1].dis + 1 <= n) {
      ff = 1;
      break;
    }
  }
  if (ff) {
    printf("%02d-%02d-%02d ", node[i].year, node[i].month, node[i].date);
    printf("%02d:%02d:%02d\n", node[i].hour, node[i].minute, node[i].second);
  } else
    puts("-1");
}
