#include <bits/stdc++.h>
using namespace std;
int main() {
  int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int n, m;
  cin >> n >> m;
  vector<int> ans;
  string s;
  int idx = 0;
  while (getline(cin, s)) {
    int month = (s[5] - '0') * 10 + (s[6] - '0');
    int day = (s[8] - '0') * 10 + (s[9] - '0');
    int hour = (s[11] - '0') * 10 + (s[12] - '0');
    int mnt = (s[14] - '0') * 10 + (s[15] - '0');
    int sec = (s[17] - '0') * 10 + (s[18] - '0');
    int totalSec = sec + mnt * 60 + hour * 3600 + day * 24 * 3600;
    for (int i = 0; i < month - 1; i++) {
      totalSec += months[i] * 24 * 3600;
    }
    while (idx < ans.size() and ans[idx] + n <= totalSec) {
      idx++;
    }
    ans.push_back(totalSec);
    if (ans.size() - idx >= m) {
      for (int i = 0; i < 19; i++) {
        printf("%c", s[i]);
      }
      puts("");
      return 0;
    }
  }
  puts("-1");
  return 0;
}
