What is wrong with this code (Matrix Search)

https://online.codingblocks.com/app/player/199544/content/197161/5063/code-challenge

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

	Scanner sc = new Scanner(System.in);
	
	int n = sc.nextInt();
	int m = sc.nextInt();
	
	int arr[][] = new int[n][m];
	
	for(int i=0 ; i<n ; i++)
		for(int j=0 ; j<m ; j++)
			arr[i][j] = sc.nextInt();		// input
	
	int item = sc.nextInt();
	
	int row=0;
	for(int i=0 ; i<n ; i++){
		if(arr[i][m-1] >= item)		// finding row
			row = i;				
	}
	
	int flag = 0;
	int low = 0, high = m-1;	// simple binary search
	while(low <= high){
		int mid = (low+high)/2;
		
		if(item < arr[row][mid])
			high = mid -1;
		else if(item > arr[row][mid])
			low = mid +1 ;
		else{
			flag = 1;
			break;
		}
	}
	System.out.println(flag);

}

}

for input:
4 4
10 20 30 40 15 25 35 45 27 29 37 48 32 33 39 50
29
correct output should be
1
debug for this