#K10651. Missing Integer in Grid

    ID: 23294 Type: Default 1000ms 256MiB

Missing Integer in Grid

Missing Integer in Grid

Given a grid of dimensions \(n \times m\) filled with positive integers, your task is to determine the smallest positive integer that does not appear in the grid. This problem tests the ability to use set-based operations and handle multi-dimensional input efficiently.

For each test case, the input starts with two integers \(n\) and \(m\) indicating the number of rows and columns respectively, followed by \(n\) lines each containing \(m\) integers. Your program should output the smallest positive integer missing from the grid for each test case.

inputFormat

The input begins with an integer \(T\) representing the number of test cases. Each test case is structured as follows:

  • The first line contains two space-separated integers \(n\) and \(m\) (\(1 \leq n, m \leq 10^3\)).
  • The next \(n\) lines each contain \(m\) space-separated positive integers that represent the grid values.

outputFormat

For each test case, output a single line with the smallest positive integer that is not present in the grid.

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

5

</p>