private static List<Node> neighbors(int i, int j, char[][] a, int M, int N) {
        List<Node> list = new ArrayList<>();
        
        if (i - 1 >= 0 && a[i-1][j] == '.') list.add(new Node(i-1, j, 0));
        if (i + 1 < M && a[i+1][j] == '.') list.add(new Node(i+1, j, 0));
        if (j - 1 >= 0 && a[i][j-1] == '.') list.add(new Node(i, j-1, 0));
        if (j + 1 < N && a[i][j+1] == '.') list.add(new Node(i, j+1, 0));
        
        return list;
    }