#include <bits/stdc++.h>
using namespace std;
int tonum(string s, int i, int j) { return (s[i] - '0') * 10 + s[j] - '0'; }
const int days[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct T {
  int mon, day, hour, min, sec;
  void make(string &s1, string &s2) {
    mon = tonum(s1, 5, 6);
    day = tonum(s1, 8, 9);
    hour = tonum(s2, 0, 1);
    min = tonum(s2, 3, 4);
    sec = tonum(s2, 6, 7);
  }
};
queue<T> Q;
int n, m;
int fuck(const T &a) {
  int ret = 0;
  for (int i = (1); i <= (a.mon - 1); i++) ret += days[i] * 24 * 60 * 60;
  for (int i = (1); i <= (a.day - 1); i++) ret += 24 * 60 * 60;
  for (int i = (0); i <= (a.hour - 1); i++) ret += 60 * 60;
  for (int i = (0); i <= (a.min - 1); i++) ret += 60;
  ret += a.sec;
  return ret;
}
int dis(const T &a, const T &b) { return fuck(b) - fuck(a); }
int main() {
  cin >> n >> m;
  string s1, s2;
  int cnt = 0;
  while (cin >> s1 >> s2) {
    T now;
    now.make(s1, s2);
    while (!Q.empty() && dis(Q.front(), now) >= n) Q.pop();
    Q.push(now);
    if (Q.size() >= m) {
      cout << s1 << " " << s2.substr(0, 8) << endl;
      return 0;
    }
    getline(cin, s1);
  }
  puts("-1");
  return 0;
}
