#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 5;
int f[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
long long mo[13], t[maxn];
long long m[maxn], d[maxn], h[maxn], mi[maxn], s[maxn];
char ss[maxn];
int main() {
  int n, q;
  int y, ans = 0, all = 0;
  long long mm, dd, hh, mimi, sss;
  scanf("%d %d", &n, &q);
  while (~scanf("%d-%I64d-%I64d %I64d:%I64d:%I64d:", &y, &mm, &dd, &hh, &mimi,
                &sss)) {
    ans++;
    gets(ss);
    m[ans] = mm, d[ans] = dd, h[ans] = hh, mi[ans] = mimi, s[ans] = sss;
    t[ans] = sss + mimi * 60 + hh * 60 * 60 + dd * 24 * 60 * 60 +
             f[mm - 1] * 24 * 60 * 60;
  }
  for (int i = 1; i <= ans; i++) {
    all = 1;
    for (int j = i + 1; j <= ans; j++) {
      if (t[j] - t[i] <= n - 1) {
        all++;
        if (all == q) {
          printf("2012-%02I64d-%02I64d %02I64d:%02I64d:%02I64d", m[j], d[j],
                 h[j], mi[j], s[j]);
          return 0;
        }
      } else
        break;
    }
  }
  printf("-1");
}
