Download

Time limit1sMemory limit128 MB

Problem

Taekhee wants to download a song that is split into several pieces. The pieces must be downloaded in order. For each piece, Taekhee knows its playback duration and the time needed to download it.

Taekhee may start listening before every piece has finished downloading. However, once playback starts, the song must continue to the end without stopping. A piece can be played only after that entire piece has been downloaded.

Find the earliest number of seconds after the download begins when Taekhee can start playback and listen to the whole song without interruption.

Input

The first line contains the number of pieces, N. (1 <= N <= 100,000)

Each of the next N lines contains two integers D and V: the playback duration of a piece and the time required to download that piece. (1 <= D, V <= 1000)

The pieces are given in download and playback order.

Output

Print the earliest number of seconds after the download begins when playback can start and continue without interruption.