One test Cases passes and the other are showing run error


import java.util.*;
public class Main {
private static Scanner sc;
public static void main(String[] args) {
// TODO Auto-generated method stub
sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int[][] mBoard=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
char ch=sc.next().charAt(0);
if(ch==‘X’) {
mBoard[i][j]=1;
}
}
}
boolean rc=blockedMazePath(mBoard,0,0,new int[n][m]);
if(!rc) {
System.out.println(-1);
}

}
public static boolean blockedMazePath(int[][] maze,int row,int col,int[][] visited) {
	if(row==maze.length-1&&col==maze[0].length-1) {
		visited[row][col]=1;
		for(int i=0;i<maze.length;i++) {
			for(int j=0;j<maze[0].length;j++) {
				System.out.print(visited[i][j]+"");
			}
			System.out.println();
		}
		visited[row][col]=0;
		return true;
	}
	if(row==maze.length||col==maze[0].length||maze[row][col]==1) {
		return false;
	}
	visited[row][col]=1;
	boolean R=blockedMazePath(maze,row,col+1,visited);
	if(R) {
		return true;
	}
		boolean D=blockedMazePath(maze,row+1,col,visited);
	if(D) {
		return true;
	}
    visited[row][col]=0;
	return false;
}

}

input format is wrong


you can see this