# Minimum Consecutive Number in Matrix – Infytq 2019 Solve

```5 6
1 3 3 3 3 9
1 6 9 2 3 9
1 2 2 5 4 9
2 2 4 5 7 9
2 4 5 6 7 2
```

```2
```

#### Solution: We strongly recommend you to try the problem first before moving to the solution. Python

```row,column=map(int,input().split(" "))
digit=[]
matrix=[]
for r in range(row):
row_numbers=list(map(int,input().split()))
matrix.append(row_numbers)
for r in range(0, row):
for c in range(0, column):
if(c < column-3): #condition for cosecutive numbers in all rows

if(matrix[r][c]==matrix[r][c+1]==matrix[r][c+2]==matrix[r][c+3]):
digit.append(matrix[r][c])

if(r < row-3):    #condition for cosecutive numbers in all columns

if(matrix[r][c]==matrix[r+1][c]==matrix[r+2][c]==matrix[r+3][c]):
digit.append(matrix[r][c])

if(c < column-3 and r >= 3): #cosecutive numbers in all left to right diagonals

if(matrix[r][c]==matrix[r-1][c+1]==matrix[r-2][c+2]==matrix[r-3][c+3]):
digit.append(matrix[r][c])

if(c >= 3 and r >= 3):   #cosecutive numbers in all left to right diagonals

if(matrix[r][c]==matrix[r-1][c-1]==matrix[r-2][c-2]==matrix[r-3][c-3]):
digit.append(matrix[r][c])

if(len(digit)==0):
print("-1")
else:
print(min(digit))
```

```5 6
1 3 3 3 3 9
1 6 9 2 3 9
1 2 2 5 4 9
2 2 4 5 7 9
2 4 5 6 7 2
```

```2
```

You Missed