#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
  ostringstream str;
  str << a;
  return str.str();
}
int string2int(string a) {
  stringstream str(a);
  int b;
  str >> b;
  return b;
}
template <class T>
inline void read(T& r) {
  r = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' or ch > '9') {
    f = (ch == '-' ? -1 : 1), ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    r = r * 10 + ch - '0', ch = getchar();
  }
  r *= f;
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
int Month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<long long> v;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  string str;
  int pos = 0;
  getchar();
  while (getline(cin, str)) {
    int month = string2int(str.substr(5, 2));
    int day = string2int(str.substr(8, 2));
    int hh = string2int(str.substr(11, 2));
    int mm = string2int(str.substr(14, 2));
    int second = string2int(str.substr(17, 2));
    long long secnd = second + mm * 60 + hh * 3600 + day * 24 * 3600;
    for (int i = int(0); i < int(month - 1); i++) secnd += Month[i] * 24 * 3600;
    v.push_back(secnd);
    while (pos < int(v.size()) && v[pos] + n <= secnd) pos++;
    if (int(v.size()) - pos >= m) {
      cout << str.substr(0, 19) << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
