Rat in maze problem

why not getting all correct
import java.util.Scanner;

public class Main {
public static void main(String agrsp[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
char a[][]=new char[n][m];
for(int i=0;i<n;i++){
String str=sc.next();
for(int j=0;j<str.length();j++){
a[i][j]=str.charAt(j);
}
}
boolean b[][]=new boolean[n][m];
fun(a,0,0,b);

    //
    if(a[0][0]!='O'&& a[0][0]!='X'){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
   else
        System.out.println(-1);

}
static int count=0;
static String str="";
public static void fun(char ch[][],int row,int col,boolean b[][]){
    if(col>=ch[0].length)
    {
        fun(ch,row+1,col-1,b);
        return;
    }
    if(row>=ch.length){

        return;
    }

    if(ch[row][col]=='X'){
        if(col-1<0)
            return;
        b[row-1][col]=false;
        fun(ch,row,col-1,b);

        return;
    }

    if(row==ch.length-1 && col==ch[0].length-1 && count==0)
    {
        b[row][col]=true;
        //System.out.println("Done");
        for(int i=0;i<b.length;i++){
            for(int j=0;j<b[0].length;j++){
                if(b[i][j])
                    ch[i][j]='1';
                else
                    ch[i][j]='0';
                //System.out.print(b[i][j]+"\t");
            }
           // System.out.println();
        }
        b[row][col]=false;
        count++;
        return;
    }
        //return;

for(int i=col;i<ch[0].length;i++,col++){
if(ch[row][i]!=‘X’){
b[row][i]=true;

}
else{
    fun(ch,row+1,i-1,b);
    return;
}

}
fun(ch,row+1,col-1,b);

    //b[row][col]=false;

}

}

Hey @Anubhav44044
try for this input
1 5
OOOOO
correct output : 1 1 1 1 1