#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-10;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
long long M[15] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char second[5000005], s[5000005], l[15];
vector<long long> a;
int main(void) {
  long long n, mm;
  cin >> n >> mm;
  scanf("\n");
  l[0] = 0;
  for (long long(i) = 0; (i) < (long long)(13); (i)++) l[i + 1] += l[i] + M[i];
  while (gets(s)) {
    long long m, d, h, mn, sec;
    sscanf(s, "2012-%I64d-%I64d %I64d:%I64d:%I64d:%s", &m, &d, &h, &mn, &sec,
           second);
    long long p = m;
    m--;
    long long rez = 0;
    if (m < 0) m = 0;
    rez = sec + 60 * mn + 3600 * h + 3600 * 24 * (d - 1);
    for (long long(i) = 0; (i) < (long long)(m); (i)++) rez += 24 * 3600 * M[i];
    a.push_back(rez);
    if (a.size() >= mm && a[a.size() - mm] + n > a.back()) {
      printf("2012-%02I64d-%02I64d %02I64d:%02I64d:%02I64d\n", p, d, h, mn,
             sec);
      exit(0);
    }
  }
  cout << -1 << endl;
  return 0;
}
