{"raw_statement":[{"iden":"statement","content":"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.\n\nHe 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.\n\nFind the earliest time when Arkady can insert the takeoff."},{"iden":"input","content":"The first line of input contains two integers $n$ and $s$ ($1 \\le n \\le 100$, $1 \\le s \\le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.\n\nEach of next $n$ lines contains two integers $h$ and $m$ ($0 \\le h \\le 23$, $0 \\le m \\le 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."},{"iden":"output","content":"Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff."},{"iden":"examples","content":"Input\n\n6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n\nOutput\n\n6 1\n\nInput\n\n16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n\nOutput\n\n24 50\n\nInput\n\n3 17\n0 30\n1 0\n12 0\n\nOutput\n\n0 0"},{"iden":"note","content":"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.\n\nIn 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.\n\nIn the third example Arkady can insert the takeoff even between the first landing."}],"translated_statement":[{"iden":"statement","content":"这些天，Arkady 在一个大型机场担任空中交通管制员。他负责一条仅用于降落的跑道。因此，他有一份未来即将降落的飞机时刻表，每架飞机降落耗时 1 分钟。\n\n他被要求在时刻表中插入一次起飞。起飞本身耗时 1 分钟，但出于安全考虑，起飞与任何降落之间必须至少间隔 s 分钟（前后均需满足）。\n\n请找出 Arkady 可以插入起飞的最早时间。\n\n输入的第一行包含两个整数 $n$ 和 $s$（$1 lt.eq n lt.eq 100$，$1 lt.eq s lt.eq 60$）——分别表示时刻表中降落的次数和降落与起飞之间允许的最小时间（分钟）。\n\n接下来的 $n$ 行，每行包含两个整数 $h$ 和 $m$（$0 lt.eq h lt.eq 23$，$0 lt.eq m lt.eq 59$）——表示从当前时刻（即当前时间为 $0$ $0$）起，每架飞机降落的时间（小时和分钟）。这些时间按递增顺序给出。\n\n请输出两个整数 $h$ 和 $m$——表示从当前时刻起，Arkady 可以插入起飞的最早时间的小时和分钟。\n\n在第一个示例中，请注意 _1:20_ 和 _3:21_ 之间的时间不足，因为每次降落和起飞都耗时 1 分钟。\n\n在第二个示例中，时刻表中没有空隙，因此 Arkady 只能在所有降落之后插入起飞。请注意，可能需要等待超过 $24$ 小时才能插入起飞。\n\n在第三个示例中，Arkady 甚至可以在第一次降落之间插入起飞。"},{"iden":"input","content":"输入的第一行包含两个整数 $n$ 和 $s$（$1 lt.eq n lt.eq 100$，$1 lt.eq s lt.eq 60$）——分别表示时刻表中降落的次数和降落与起飞之间允许的最小时间（分钟）。接下来的 $n$ 行，每行包含两个整数 $h$ 和 $m$（$0 lt.eq h lt.eq 23$，$0 lt.eq m lt.eq 59$）——表示从当前时刻（即当前时间为 $0$ $0$）起，每架飞机降落的时间（小时和分钟）。这些时间按递增顺序给出。"},{"iden":"output","content":"请输出两个整数 $h$ 和 $m$——表示从当前时刻起，Arkady 可以插入起飞的最早时间的小时和分钟。"},{"iden":"examples","content":"输入\n6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n输出\n6 1\n\n输入\n16 5\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n输出\n24 50\n\n输入\n3 1\n7 30\n1 0\n12 0\n输出\n0 0"},{"iden":"note","content":"在第一个示例中，请注意 _1:20_ 和 _3:21_ 之间的时间不足，因为每次降落和起飞都耗时 1 分钟。在第二个示例中，时刻表中没有空隙，因此 Arkady 只能在所有降落之后插入起飞。请注意，可能需要等待超过 $24$ 小时才能插入起飞。在第三个示例中，Arkady 甚至可以在第一次降落之间插入起飞。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of landings, and $ s \\in \\mathbb{Z} $ be the minimum required safety gap (in minutes).  \nLet $ L = \\{(h_i, m_i) \\mid i \\in \\{1, \\dots, n\\}\\} $ be the sequence of landing times, where each $ (h_i, m_i) $ represents the time in hours and minutes from the current moment, converted to total minutes:  \n$$ t_i = 60 \\cdot h_i + m_i $$  \nThus, define $ T = (t_1, t_2, \\dots, t_n) $, with $ t_1 < t_2 < \\dots < t_n $, and each $ t_i \\in \\mathbb{N}_0 $.\n\nEach landing occupies the interval $ [t_i, t_i + 1) $.\n\nA takeoff requires a 1-minute slot $ [x, x+1) $, and must satisfy:  \n$$ [x, x+1) \\cap [t_i, t_i + 1) = \\emptyset \\quad \\text{and} \\quad x + 1 + s \\le t_i, \\quad t_i + 1 + s \\le x $$  \nfor all $ i \\in \\{1, \\dots, n\\} $.\n\nEquivalently, for all $ i $:  \n$$ x \\le t_i - s - 1 \\quad \\text{or} \\quad x \\ge t_i + 1 + s $$\n\n**Constraints**  \n1. $ 1 \\le n \\le 100 $  \n2. $ 1 \\le s \\le 60 $  \n3. $ 0 \\le h_i \\le 23 $, $ 0 \\le m_i \\le 59 $, so $ 0 \\le t_i \\le 1439 $  \n4. $ t_1 < t_2 < \\dots < t_n $\n\n**Objective**  \nFind the smallest $ x \\in \\mathbb{N}_0 $ such that:  \n- $ x \\ge 0 $,  \n- $ [x, x+1) $ does not violate the safety constraint with any landing, i.e.,  \n  $$ \\forall i \\in \\{1, \\dots, n\\}, \\quad x + 1 + s \\le t_i \\quad \\text{or} \\quad t_i + 1 + s \\le x $$  \n- and among all such valid $ x $, choose the minimal one.\n\nThen output $ h = \\left\\lfloor \\frac{x}{60} \\right\\rfloor $, $ m = x \\bmod 60 $.","simple_statement":null,"has_page_source":false}