Testing LEDs

시간 제한2초메모리 제한2048 MB

요약
타임스탬프와 LED 상태를 담은 기록 N개가 주어질 때, 상태가 꺼짐인 기록 중 가장 이른 시각을 출력하고, 꺼진 기록이 없으면 -1을 출력한다.
난이도

쉬움10점 중 2점

유형
구현, 배열
정답자
아직 제출이 없습니다

문제

LEDs are an amazing technology, in part due to their longevity. But they can’t last forever right? So you decide to put it to the test; you turn on an LED, and a machine periodically records the time in milliseconds since you started. Eventually it turns off! Your machine kept recording though, and unforunately your data is all jumbled up! What is the first time the machine recorded the LED being off?

Note that the LED may turn back on; you want to find the very first time the LED was recorded being off.

입력

The first line of input contains the integer NN (1≤N≤1051≤N≤10^5). The following NN lines consist of 22 integers MM (0≤M<2310≤M<2^{31}) and OO (O∈0,1O\in\\{0,1\\}), where MM is the time this recording was taken in milliseconds, and OO denotes whether the LED was on or off. The number 11 corresponds to the LED being on, and 00 off.

출력

Output a single integer denoting the time of the first recording where the LED was off, or output −1-1 if it was never off for any recording.

예제3

  1. 예제 1

    입력
    4
    400 0
    100 1
    300 0
    200 1
    
    예상 출력
    300
    
  2. 예제 2

    입력
    3
    10 1
    2010 1
    150 1
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    6
    250 0
    25 1
    100 0
    50 0
    200 1
    150 1
    
    예상 출력
    50