#include <bits/stdc++.h>
using namespace std;
struct Tpoint {
  double x, y;
  Tpoint() {}
  Tpoint(double _x, double _y) {
    x = _x;
    y = _y;
  }
  inline void read() { scanf("%lf%lf", &x, &y); }
  inline void show() { printf("%lf %lf\n", x, y); }
  inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }
};
inline Tpoint operator+(const Tpoint &a, const Tpoint &b) {
  return Tpoint(a.x + b.x, a.y + b.y);
}
inline Tpoint operator-(const Tpoint &a, const Tpoint &b) {
  return Tpoint(a.x - b.x, a.y - b.y);
}
inline Tpoint operator*(const Tpoint &a, const double &b) {
  return Tpoint(a.x * b, a.y * b);
}
inline Tpoint operator/(const Tpoint &a, const double &b) {
  return Tpoint(a.x / b, a.y / b);
}
inline double det(const Tpoint &a, const Tpoint &b) {
  return a.x * b.y - a.y * b.x;
}
inline double dot(const Tpoint &a, const Tpoint &b) {
  return a.x * b.x + a.y * b.y;
}
const int days[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int parse(char line[]) {
  for (int i = 0; line[i]; ++i) {
    if (line[i] < '0' || line[i] > '9') {
      line[i] = ' ';
    }
  }
  stringstream in(line);
  int year, month, day, hour, minute, second;
  in >> year >> month >> day >> hour >> minute >> second;
  for (int i = 1; i < month; ++i) {
    day += days[i];
  }
  hour += day * 24;
  minute += hour * 60;
  second += minute * 60;
  return second;
}
char line[10000000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  gets(line);
  queue<int> q;
  for (; gets(line);) {
    string out = "";
    for (int i = 0; i < 19; ++i) {
      out += line[i];
    }
    int cur = parse(line);
    while (q.size() && q.front() <= cur - n) {
      q.pop();
    }
    q.push(cur);
    if (q.size() >= m) {
      cout << out << endl;
      goto Break;
    }
  }
  cout << -1 << endl;
Break:;
  return 0;
}
