Bored Board Judges


Amir is preparing his set for the Street Rules Olympic Skateboarding. The MAPS team has prepared a rectangular course, featuring many different interesting elements to make tricks on.

As part of his set, Amir will make two runs through the grid - one up the grid, at which point he turns around at the half-pipe, and then a second down the grid.

Amir can start and finish his sets at any position on the lowest/highest rows of the grid. On Amir's run, he must always move towards the other end of the grid, and while doing so, he may also move 1 unit left/right.

Amir has spent some time studying the grid, and knows if he performs a trick on this cell, how many points he will score from the judges. Let's call this the "trick score". However, if both of his runs feature a trick on the same grid square, he knows that he will receive a reduced score the second time round. Let's call this the "dupe score".

Can you help Amir determine the maximum score he can achieve on the grid specified?

Input

Input will begin with a line containing 2 integers, nn (2≤n≤50002 \leq n \leq 5000) and mm (1≤m≤501 \leq m \leq 50), the dimensions of the grid (height and width, respectively).

nn lines then follow, each containing mm pairs of space separated integers (So 2m2m integers), representing a single row of the grid.

The first number in each pair is the trick score for the related grid cell ti,jt_{i, j}, and the second number in each pair is the dupe score for the related grid cell di,jd_{i, j} (0≤di,j≤ti,j≤1090 \leq d_{i, j} \leq t_{i, j} \leq 10^9).

The first line of the grid is the top-row (midpoint, adjacent to the half-pipe), and the last line of the grid is the bottom-row (starting/ending point)

Output

Output a single integer, representing the maximum possible score achievable for this grid.

Example 1

Input 1
5 4
6 4 10 5 7 7 3 1
6 6 6 6 6 6 6 6
1 0 2 1 13 6 10 10
11 10 10 9 1 1 1 1
5 2 4 4 6 2 7 1
Output 1
78
Explanation

One possible answer to the sample is demonstrated below:

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.