LearnPy Hub
← Arena
AdvancedRating 1800

Swim in Rising Water

Cell heights are given. At time t you can swim through any cell with height ≤ t, moving up, down, left or right. Print the least time at which you can get from the top-left to the bottom-right cell.

Input

n, then n rows of heights.

Output

One integer.

Sample 1

Input
2
0 2
1 3
Output
3

Sample 2

Input
5
0 1 2 3 4
24 23 22 21 5
12 13 14 15 16
11 17 18 19 20
10 9 8 7 6
Output
16
solution.py
Output appears here
Swim in Rising Water · Python Arena problem · LearnPy Hub