Problem Statement Given a matrix of size N*M,also the matrix is sorted row wise & the total number of elements in the matrix is guaranteed to be …