#include <bits/stdc++.h>
namespace solution {
using namespace std;
const string NONE = "-1";
int n, m;
deque<int> Q;
bool getline(string& line) {
  if (!getline(cin, line)) return false;
  if (*line.rbegin() == '\r') line = line.substr(0, line.size() - 1);
  return true;
}
void replace(string& s, char a, char b) { replace(s.begin(), s.end(), a, b); }
struct Solution {
  void init() { Q.clear(); }
  void input() {
    string line;
    getline(line);
    istringstream iss(line);
    iss >> n >> m;
  }
  int get_deli(string& s) {
    int n = s.size();
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == ':') cnt++;
      if (cnt >= 3) return i;
    }
    return 0;
  }
  int get_days(int m) {
    int d[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    return accumulate(d, d + m, 0);
  }
  string solve() {
    string line, backup, left;
    while (getline(line)) {
      backup = left = line.substr(0, 19);
      replace(left, '-', ' ');
      replace(left, ':', ' ');
      istringstream iss(left);
      int y, mo, d, hh, mm, ss;
      iss >> y >> mo >> d >> hh >> mm >> ss;
      d += get_days(mo);
      hh += d * 24;
      mm += hh * 60;
      ss += mm * 60;
      Q.push_back(ss);
      while ((!Q.empty()) && (ss - *Q.begin() >= n)) {
        Q.pop_front();
      }
      if ((int)Q.size() >= m) return backup;
    }
    return NONE;
  }
  int run() {
    init();
    input();
    cout << solve() << endl;
    return 0;
  }
};
}  // namespace solution
int main() { return solution::Solution().run(); }
