#include <bits/stdc++.h>
using namespace std;
const int LIM = 200, INF = 1e+9;
const double PI = 3.1415926535, EPS = 1e-7;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
T gcd(T a, T b) {
  return a == 0 ? b : gcd(b % a, a);
}
int n, m;
int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<long long> a;
string s;
int main() {
  cin >> m >> n;
  int pos = 0;
  while (cin >> s) {
    string ans = s;
    int b = atoi(s.substr(5, 7).c_str());
    int c = atoi(s.substr(8, 10).c_str());
    long long p = 0;
    for (int i = 0; i < b - 1; i++) p += days[i];
    p += c;
    p *= 24 * 60 * 60;
    cin >> s;
    ans += " " + s;
    int x = atoi(s.substr(0, 2).c_str());
    int y = atoi(s.substr(3, 5).c_str());
    int z = atoi(s.substr(6, 8).c_str());
    p += x * 60 * 60 + y * 60 + z;
    getline(cin, s);
    a.push_back(p);
    while (a[pos] <= p - m) pos++;
    if (a.size() - pos >= (unsigned)n) {
      cout << ans.substr(0, 19);
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
