improve lc search in 2D matrix (O(m+n))