What is wrong in the code?

Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();

	int[][] arr= new int[row][col];
	
	for(int i=0;i<row;i++) {
		for(int j =0; j<col;j++) {
			arr[i][j] = sc.nextInt();
			
		}
	}

	
	int val = sc.nextInt();
	boolean flag=false;
	
	for(int i=0;i<row;i++) {
		for(int j =0; j<col;j++) {

			if(arr[i][j]==val)
				flag=true;
			else
				flag = false;
		}
	}
	
	if(flag==true)
	System.out.println("1");
	else
		System.out.println("0");

for the test case:
1 6
18 21 27 38 55 67
55
the output should be 1
debug for this