These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts 1 minute.

He was asked to insert one takeoff in the schedule. The takeoff takes 1 minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least s minutes from both sides.

Find the earliest time when Arkady can insert the takeoff.

Input

The first line of input contains two integers n and s (1 ≤ n ≤ 100, 1 ≤ s ≤ 60) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.

Each of next n lines contains two integers h and m (0 ≤ h ≤ 23, 0 ≤ m ≤ 59) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is 0 0). These times are given in increasing order.

Output

Print two integers h and m — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.

Examples

Input

6 60
0 0
1 20
3 21
5 0
19 30
23 40


Output

6 1


Input

16 50
0 30
1 20
3 0
4 30
6 10
7 50
9 30
11 10
12 50
14 30
16 10
17 50
19 30
21 10
22 50
23 59


Output

24 50


Input

3 17
0 30
1 0
12 0


Output

0 0

Note

In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.

In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than 24 hours to insert the takeoff.

In the third example Arkady can insert the takeoff even between the first landing.
import java.util.*;
import java.io.*;
import java.text.*;

public class Solution{
    static final long mod = (long)1e9+7, IINF = (long)1e19;
    static int MAX = (int)1e6+1, MX = (int)1e7+1, INF = (int)1e7;
    static final double eps = 1e-8;
    static FastReader in;
    static PrintWriter out;
    static boolean multipleTC = false;
    static DecimalFormat df = new DecimalFormat("0.0000000");
    public static void main(String[] args) throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        for(int i = 1, t = (multipleTC)?ni():1; i<=t; i++)solve(i);
        out.flush();
        out.close();
    }
    
    static void solve(int TC){
        int n = ni(), s = ni();
        int prev = ni()*60+ni(), ans = -1;
        if(prev>=s+1)ans= 0;
        for(int i = 1; i< n && ans == -1; i++){
            int cur = ni()*60+ni();
            if(cur-prev>=2*s+2)ans = prev+s+1;
            else prev = cur;
        }
        if(ans==-1)ans = prev+s+1;
        pn((ans/60)+" "+ (ans%60));
    }
   
    static long modPow(long a, long p){
        long o = 1;
        while(p>0){
            if(p%2==1)o = (a*o)%mod;
            p/=2;
            a = (a*a)%mod;
        }
        return o;
    }

    static int[] ia(int n){
        int[] out = new int[n];
        for(int i = 0; i< n; i++)out[i] = ni();
        return out;
    }

    static long[] la(int n){
        long[] out = new long[n];
        for(int i = 0; i< n; i++)out[i] = nl();
        return out;
    }

    static long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

    static void p(Object o){out.print(o);}
    static void pn(Object o){out.println(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static String n(){return in.next();}
    static String nln(){return in.nextLine();}
    static int ni(){return Integer.parseInt(in.next());}
    static long nl(){return Long.parseLong(in.next());}
    static double nd(){return Double.parseDouble(in.next());}

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
} 