#include <bits/stdc++.h>
using namespace std;
int n, m, N;
char str[1000005];
string ST[5000005];
vector<long long> v;
long long getTime(string S) {
  for (int i = 0; i < 30; ++i) {
    if (S[i] == '-' || S[i] == ':') S[i] = ' ';
  }
  stringstream ss(S);
  long long t;
  ss >> t;
  long long ret = 10000;
  ss >> t;
  t--;
  for (int i = 1; i <= t; ++i) {
    if (i == 2)
      ret += (i)*29 * 24 * 3600;
    else if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 ||
             i == 12)
      ret += (i)*31 * 24 * 3600;
    else
      ret += (i)*30 * 24 * 3600;
  }
  ss >> t;
  ret += (t - 1) * 24 * 3600;
  ss >> t;
  ret += t * 3600;
  ss >> t;
  ret += t * 60;
  ss >> t;
  ret += t;
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  gets(str);
  int i = -1;
  while (gets(str)) {
    string S;
    for (int j = 0; j < 30; ++j) S.push_back(str[j]);
    ST[++i] = S;
    v.push_back(getTime(S)), N = v.size();
    int j = lower_bound(v.begin(), v.end(), v[i] - n + 1) - v.begin();
    if (j < 0 || j >= N || i - j + 1 < m) continue;
    cout << ST[i].substr(0, 19);
    return 0;
  }
  cout << -1;
  return 0;
}
