#include <bits/stdc++.h>
using namespace std;
string Time[500000];
int X[500000];
int GetNumber() {
  getchar();
  int X = (getchar() - 48) * 10;
  return X + getchar() - 48;
}
string S(int X) {
  string T = "";
  T += X / 10 + 48;
  T += X % 10 + 48;
  return T;
}
int GetDay(int Month, int Day) {
  int Ans = Day;
  for (int i = 1; i < Month; i++)
    if (i == 2)
      Ans += 29;
    else if (i == 4 || i == 6 || i == 9 || i == 11)
      Ans += 30;
    else
      Ans += 31;
  return Ans;
}
bool Get(int N) {
  char c = getchar();
  while (c = getchar(), c != -1 && c != '2')
    ;
  if (c == -1) return false;
  for (int i = 0; i < 3; i++) getchar();
  int Month = GetNumber();
  int Day = GetNumber();
  int Hour = GetNumber();
  int Minute = GetNumber();
  int Second = GetNumber();
  Time[N] = "2012-" + S(Month) + '-' + S(Day) + ' ' + S(Hour) + ':' +
            S(Minute) + ':' + S(Second);
  X[N] = GetDay(Month, Day) * 86400 + Hour * 3600 + Minute * 60 + Second;
  return true;
}
int main() {
  int MaxTime, Step;
  scanf("%d%d", &MaxTime, &Step);
  int N = 0;
  while (Get(N)) N++;
  for (int i = 0, j = Step - 1; j < N; i++, j++)
    if (X[j] - X[i] < MaxTime) {
      cout << Time[j] << endl;
      return 0;
    }
  printf("-1\n");
  return 0;
}
