#include <bits/stdc++.h>
using namespace std;
struct Counter {
  static int k;
  Counter() { k++; }
  ~Counter() { k--; }
};
int Counter::k = 0;
template <typename T>
void pr(const string& name, T t) {
  cout << name << " = " << t << endl;
}
template <typename T, typename... Types>
void pr(const string& names, T t, Types... rest) {
  auto comma_pos = names.find(',');
  cout << names.substr(0, comma_pos) << " = " << t << ", ";
  auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
  pr(string(names, next_name_pos), rest...);
}
void mod(long long& a, long long b) {
  a %= b;
  if (a < 0) a += b;
}
const long long MOD = 1000000007;
deque<long long> DQ;
long long Days[15], N, M;
int main() {
  cin >> N >> M;
  string line;
  Days[1] = 0;
  Days[2] = 31;
  Days[3] = 59;
  Days[4] = 90;
  Days[5] = 120;
  Days[6] = 151;
  Days[7] = 181;
  Days[8] = 212;
  Days[9] = 243;
  Days[10] = 273;
  Days[11] = 304;
  Days[12] = 334;
  getline(cin, line);
  while (true) {
    getline(cin, line);
    if (cin.eof()) break;
    long long year = 0, month = 0, day = 0;
    for (int i = (0); i <= (3); i++) year = 10 * year + line[i] - '0';
    for (int i = (5); i <= (6); i++) month = 10 * month + line[i] - '0';
    for (int i = (8); i <= (9); i++) day = 10 * day + line[i] - '0';
    long long days = 365 * (year - 1) + Days[month] + day - 1;
    days += (year - 1) / 4;
    if (year % 4 == 0 && month > 2) days++;
    long long hr = 10 * (line[11] - '0') + line[12] - '0';
    long long mn = 10 * (line[14] - '0') + line[15] - '0';
    long long sc = 10 * (line[17] - '0') + line[18] - '0';
    long long sec = days * 60 * 60 * 24 + 3600 * hr + 60 * mn + sc;
    if (!DQ.empty() && sec - DQ.front() >= N) DQ.pop_front();
    DQ.push_back(sec);
    if (DQ.size() >= M) {
      cout << line.substr(0, 19) << "\n";
      return 0;
    }
  }
  cout << "-1";
}
