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 sun.font.DelegatingShape;
import sun.misc.IOUtils;
import sun.nio.cs.KOI8_U;

import javax.smartcardio.ATR;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.math.*;
import java.lang.*;

public class AA implements Runnable {


    public void run() {
        InputReader sc = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int i=0,j=0,k=0;
        int t=0;
        //t=sc.nextInt();
        for(int testcase = 0;testcase < t; testcase++) {
        }
        int n=sc.nextInt();
        int mins=sc.nextInt();
        long minreq=(mins*2)+1;
        long ans=0;
        boolean found=false;
        long arr[]=new long[n];
        for (i=0;i<n;i++)
        {
            arr[i]=sc.nextInt()*60;
            arr[i]+=sc.nextInt();
            if (i==0&&arr[i]>mins)
            {
                found=true;
                ans=0;
            }
            if (!found&&i>0&&arr[i]-arr[i-1]>minreq)
            {
                found=true;
                ans=arr[i-1]+mins+1;
            }
        }
        if (!found)
            ans=arr[n-1]+mins+1;
        out.println((ans/60)+" "+(ans%60));

//================================================================================================================================
        out.flush();
        out.close();
    }

//================================================================================================================================
public static int[] sa(int n,InputReader sc)
{
    int inparr[]=new int[n];
    for (int i=0;i<n;i++)
        inparr[i]=sc.nextInt();
    return inparr;
}

    public static long gcd(long a,long b){
        return (a%b==0l)?b:gcd(b,a%b);
    }
    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }
    public int egcd(int a, int b) {
        if (a == 0)
            return b;

        while (b != 0) {
            if (a > b)
                a = a - b;
            else
                b = b - a;
        }

        return a;
    }



    public int countChar(String str, char c)
    {
        int count = 0;
        for(int i=0; i < str.length(); i++)
        {    if(str.charAt(i) == c)
            count++;
        }
        return count;
    }
    static int binSearch(Integer[] inparr, int number){
        int left=0,right=inparr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(inparr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static int binSearch(int[] inparr, int number){
        int left=0,right=inparr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(inparr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static class Pair
    {
        int a,b;
        Pair(int aa,int bb)
        {
            a=aa;
            b=bb;
        }
        String get()
        {
            return a+" "+b;
        }
        String getrev()
        {
            return b+" "+a;
        }
    }

    static boolean isPrime(long n) {
        if(n < 2) return false;
        if(n == 2 || n == 3) return true;
        if(n%2 == 0 || n%3 == 0) return false;
        long sqrtN = (long)Math.sqrt(n)+1;
        for(long i = 6L; i <= sqrtN; i += 6) {
            if(n%(i-1) == 0 || n%(i+1) == 0) return false;
        }
        return true;
    }
    static long factorial(long n)
    {
        if (n == 0)
            return 1;
        return n*factorial(n-1);
    }
//================================================================================================================================

    static class InputReader
    {
        BufferedReader br;
        StringTokenizer st;

        public InputReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

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

    public static void main(String args[]) throws Exception {
        new Thread(null, new AA(),"Main",1<<27).start();
    }
}
