← Home
#include<bits/stdc++.h>
using namespace std;
#define _ 200005
int n,m,t;string s;queue<int>b;
int a[12]={0,31,60,91,121,152,182,213,244,274,305,335};
int p(int x,int y){return (s[x]-48)*10+s[y]-48;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;cin.get();
	while(getline(cin,s)){
		t=(a[p(5,6)-1]+p(8,9))*86400+p(11,12)*3600+p(14,15)*60+p(17,18);
		b.push(t);
		while(b.size()&&b.front()<=t-n)b.pop();
		if(b.size()>=m)return cout<<s.substr(0,19)<<'\n',0;
	}
	cout<<"-1\n";
}