#K69517. Minimum Steps to Collect All Unique Integers

    ID: 33104 Type: Default 1000ms 256MiB

Minimum Steps to Collect All Unique Integers

Minimum Steps to Collect All Unique Integers

You are given a grid of size \(n \times m\) filled with integers. Starting from the top-left cell (\(0,0\)) and moving only right or down, you have to reach the bottom-right cell (\(n-1, m-1\)). Although each cell contains an integer, as you traverse the grid you collect each integer if it has not been collected before. The goal, however, is to simply determine the minimum number of steps required to travel from the top-left to the bottom-right cell. Under these movement constraints, the minimum number of steps is given by \(n + m - 2\).

Note: The grid values do not affect the number of steps because any valid path from the start to the finish (when moving only right or down) will always have exactly \(n + m - 2\) steps.

inputFormat

The first line contains two integers \(n\) and \(m\), representing the number of rows and columns, respectively. The next \(n\) lines each contain \(m\) space-separated integers representing the grid.

outputFormat

Output a single integer representing the minimum number of steps needed to travel from the top-left cell to the bottom-right cell.

## sample
3 3
1 2 3
4 5 6
7 8 9
4