Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-eng-qimmat-yol

Most valuable path

Medium 1000 ms 128 MB 65%
Share

An integer matrix of size $n \times m$ is given. You walk from the top-left cell $(1, 1)$ to the bottom-right cell $(n, m)$, moving only right or down at each step. Find the largest possible sum of the elements of all cells on the path (the start and the finish included).

The path with the largest sum from the top-left to the bottom-right corner

Input

The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.

Output

One integer — the largest path sum.

Note

$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$

Examples

Input #1
3 3
1 3 1
1 5 1
4 2 1
Output #1
12
Input #2
2 2
-1 -5
-2 -1
Output #2
-4

Sign in to submit a solution

Signing up is free and takes a minute.