Find the maximum (of the function)#8765

Find the maximum (of the function)

1 second
64 megabytes
Very easy

You have a field divided into n \times m squares. Rows are numbered from to from top to bottom, and columns from to from left to right. Your robot starts at cell .

Each cell contains an integer. The robot can see only the number in the cell it currently occupies. The robot can move left, right, down, and up, but does not know the dimensions of the field.

Your task is to find the maximum number on the field using the robot.

Input

The first line contains two integers and (1 \leq n, m \leq 100) — the dimensions of the field.

Each of the next rows contains integers a_{i1}, a_{i2}, \ldots, a_{im} (0 \leq |a_{ij}| \leq 10^9) — the numbers on the field.

Interaction

You need to implement the following function:

integer solve()

  • This function should return a single integer — the maximum number on the field.

You can use the following functions:

integer getValue()

  • Returns the integer in the cell where the robot is currently located.

boolean canMoveLeft()boolean canMoveRight()boolean canMoveUp()boolean canMoveDown()

  • Each function returns true if the robot can move in the specified direction without going out of bounds, otherwise false.

void moveLeft()void moveRight()void moveUp()void moveDown()

  • Each function moves the robot one cell in the specified direction.

Output

Output a single integer — the maximum number on the field.

Examples

a = \begin{pmatrix} 1 & 3 & 4 \\ 8 & 1 & 5 \end{pmatrix}

Let n = 2, m = 3, and

If the robot is at cell , the functions canMoveLeft and canMoveUp will return false, while canMoveRight and canMoveDown will return true. Calling getValue at that position will return .

If you call moveDown, the robot will move to position . Then, canMoveDown will return false, and getValue will return .

Note: The example illustrates how to use the functions, not how to solve the problem.

Example 1

Loading
Loading

Scoring

  1. (up to 50 points) n \leq 1;

    • Let be the minimum number of moves needed to definitely find the answer, and be the maximum number of moves you made in all tests. You will score \max(\lfloor 50 - \sqrt{t - c} \rfloor, 0) points.

  2. (up to 50 points) without additional restrictions;

    • Let be the minimum number of moves needed to definitely find the answer, and be the maximum number of moves you made in all tests. You will score \max\left(\lfloor 50 - (1/3.0)^{(t-c)} \rfloor, 0\right) points.