private int helper(int n, int m, int[][] men, int[][] obstacleGrid) {

        if (n <= 0 || m <= 0) {
            return 0;
        }
        //the start position, if not obstacle, return 1
        if (n == 1 && m == 1 && obstacleGrid[0][0] != 1) {
            return 1;
        }//else will be check in the recursive equation 

        if (men[n][m] != 0) {
            return men[n][m];
        } else {
            men[n][m] = obstacleGrid[n - 1][m - 1] == 1 ? 0 : helper(n - 1, m, men, obstacleGrid) + helper(n, m - 1, men, obstacleGrid);
        }
        return men[n][m];
    }