#include <bits/stdc++.h>
using namespace std;
void solve() {}
int months[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char str[5123456];
long long dandtime(int mon, int dd, int hh, int mn, int ss) {
  long long ans = 0;
  for (int i = 0; i < (mon); i++) {
    ans += months[i] * 24 * 60 * 60LL;
  }
  ans += dd * 24 * 60 * 60LL;
  ans += hh * 60 * 60LL;
  ans += mn * 60LL;
  ans += ss;
  return ans;
}
int main() {
  int n, m, yr, mon, dt, hr, mn, ss;
  cin >> n >> m;
  vector<pair<long long, string> > v;
  pair<long long, string> S;
  getchar();
  while (scanf("%[^\n]\n", str) != EOF) {
    sscanf(str, "%d-%d-%d %d:%d:%d:", &yr, &mon, &dt, &hr, &mn, &ss);
    S.second = str;
    S.first = dandtime(mon, dt, hr, mn, ss);
    v.push_back(S);
  }
  sort(v.begin(), v.end());
  int mless = 0;
  int mcount = 1;
  int i = 1;
  while (i < v.size()) {
    if (v[i].first - v[mless].first >= n) {
      mless++;
      mcount--;
    } else {
      mcount++;
      if (mcount >= m) {
        v[i].second.resize(19);
        cout << v[i].second << endl;
        return 0;
      }
      i++;
    }
  }
  if (mcount >= m) {
    v[0].second.resize(19);
    cout << v[0].second << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
