function solution(maps) {
let X=[-1,1,0,0];
let Y=[0,0,1,-1];
let visited=new Array(maps.length).fill(0).map(e=>new Array(maps.length).fill(0));
visited[0][0]=1;
let arr=[[0,0]];
while(arr.length){
for(let j=0;j<arr.length;j++){
let [x,y]=arr.shift();
for(let i=0;i<4;i++){
let nx=x+X[i];
let ny=y+Y[i];
if(nx>=0 && nx<maps.length && ny>=0 && ny<maps[0].length && maps[nx][ny]!==0 && !visited[nx][ny]){
arr.push([nx,ny]);
visited[nx][ny]=1;
maps[nx][ny]=maps[x][y]+1;
}
}
}
}
return maps[maps.length-1][maps[0].length-1]!==1?maps[maps.length-1][maps[0].length-1]:-1;
}