#C3818. Largest Prime in Grid Rows

    ID: 47287 Type: Default 1000ms 256MiB

Largest Prime in Grid Rows

Largest Prime in Grid Rows

You are given an n x m grid filled with integers. Your task is to determine the largest prime number in each row.

If a row does not contain any prime numbers, output -1 for that row.

The prime checking should be done according to the standard definition:

\( \text{A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.} \)

Input is read from stdin and the result should be output to stdout as described below.

inputFormat

The first line contains two integers n and m, representing the number of rows and columns of the grid respectively.

The following n lines each contain m space separated integers representing the grid values.

Input is read from stdin.

outputFormat

Print a single line containing n integers separated by spaces. The \(i\)-th integer should be the largest prime number in the \(i\)-th row of the grid, or -1 if that row contains no prime numbers.

Output is written to stdout.

## sample
3 4
10 15 3 7
5 6 8 13
1 4 8 6
7 13 -1