335. Count Negative Numbers in a Sorted Matrix

0

Easy

Given a matrix grid with dimensions m x n, where the elements are sorted in non-increasing order both row-wise and column-wise, determine the number of negative numbers in the grid.

Input Format

The input consists of two integers, m and n, on the first line, representing the dimensions of the matrix. The following m lines contain n integers each, representing the elements of the matrix.

Output Format

Output a single integer, representing the count of negative numbers in the matrix.

Example

Input

4 4
4 3 2 -1
3 2 1 -1
1 1 -1 -2
-1 -1 -2 -3

Output

8

Constraints

m and n are the dimensions of the matrix grid, where m is the number of rows and n is the number of columns. The values of m and n are equal to the length of the grid array. The values of m and n are integers between 1 and 100, inclusive. The values of the elements in the grid array are integers between -100 and 100, inclusive.

Loading...

View Submissions

Console