P17390 [PacNW 2025] Training, Round 4

Description

Ashley is training for another programming contest. Her coach Tom has prepared a list of problems that she must solve in order. Every problem has a positive integer implementation difficulty and thinking difficulty. Ashley starts with some implementation skill and thinking skill. She can solve a problem if and only if both skills are at least the corresponding difficulties. After solving a problem, exactly one of her two skills increases by $1$, and she chooses which one. Find the minimum possible sum of Ashley's two initial skill levels that allows her to solve every problem in order.

Input Format

The first line contains an integer $n$ ($1\le n\le50$). Each of the next $n$ lines contains two integers $i$ and $t$ ($1\le i,t\le10^9$), the implementation and thinking difficulties of one problem. Problems are given in the required order.

Output Format

Output the minimum possible sum of Ashley's initial implementation and thinking skills.