Doubt regarding Matrix Search Problem

This is my code .

import java.util.*;
public class Main {
public static void main(String args[]) {

	Scanner scan = new Scanner(System.in) ;
	int n = scan.nextInt() ;
	int m = scan.nextInt() ;
	int[][] matrix = new int[n][m] ;
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < m ; j ++){
			matrix[i][j] = scan.nextInt() ;
		}
	}
	int item = scan.nextInt() ;
	System.out.print(bsm(matrix , item)) ;
}

public static int bsm(int[][] matrix , int item){

	for(int row = 0 ; row < matrix.length ; ){

		if(item > matrix[row][matrix[0].length-1]){
			row ++ ;
		}
		else{
			return bs(matrix[row],item) ;
		}
	}
	return 0 ;
}

public static int bs(int[] arr , int item){

	int low = 0 ;
	int high = arr.length-1 ;
	while(low <= high){

		int mid = (low+high)/2 ;
		if(item == arr[mid]){
			return 1 ;
		}
		else if(item > arr[mid]){
			low = mid+1 ;
		}
		else{
			high = mid-1 ;
		}
	}

	return 0 ;
}

}

Only 1 test case is failing . Can you tell me where did I go wrong in the logic ?

@Lalit2142,
Test case:
4 4
10 20 30 40 15 25 35 45 27 29 37 48 32 33 39 50
29

Your output:
0
Correct Output:
1