```
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
try:
N, M = len(matrix), len(matrix[0])
i, j = 0, M - 1
while(1):
cur = matrix[i][j]
if(target == cur):
return True
elif(target > cur):
i += 1
else:
j -= 1
except:
return False
```

without any redundant border check. use try, except to catch the last "search failure" and the special empty case.