http://codeforces.com/problemset/problem/245/F
/*60ms,16600KB*/
#include<bits/stdc++.h>
using namespace std;
const int mx = 5000005;
const int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int day2s = 24 * 3600;
char str[mx];
int t[3000005], mm, mo, d, h, m, s, cnt;
inline int cnt_s()
{
int ans = 0;
for (int i = 1; i < mo; ++i) ans += month[i];
ans += d - 1;
ans *= day2s;
ans += h * 3600 + m * 60 + s;
return ans;
}
inline bool judge(int now)
{
return t + cnt - lower_bound(t, t + cnt, now) >= mm;
}
int main()
{
int len;
scanf("%d%d", &len, &mm);
getchar();
bool ok = false;
while (gets(str))
{
sscanf(str, "%*d%*c%d%*c%d %d%*c%d%*c%d", &mo, &d, &h, &m, &s);
t[cnt++] = cnt_s();
if (judge(t[cnt - 1] - len + 1))
{
printf("2012-%02d-%02d %02d:%02d:%02d\n", mo, d, h, m, s);
ok = true;
break;
}
}
if (!ok) puts("-1");
return 0;
}