class Solution:
    def uniquePathsWithObstacles(self, obstacleGrid):
        if not obstacleGrid or len(obstacleGrid[0])==0:
            return 0
        n, m = len(obstacleGrid), len(obstacleGrid[0])
        if n==1 and sum(x for x in obstacleGrid[0]):
            return 0
        if m==1 and n!=1 and sum(x[0] for x in obstacleGrid)>0:
            return 0
        if obstacleGrid[0][0]==1 or obstacleGrid[n-1][m-1]==1:
            return 0
        num=[[0 for i in range(m)]for j in range(n)]
        for i in range(m):
            if obstacleGrid[0][i]==0:
                num[0][i]=1
            else:
                break
        for i in range(n):
            if obstacleGrid[i][0]==0:
                num[i][0]=1
            else:
                break
        for i in range(1,n,1):
            for j in range(1,m,1):
                if obstacleGrid[i][j]!=1:
                    num[i][j]=num[i-1][j]+num[i][j-1]
        return num[n-1][m-1]
s=Solution()
obstacleGrid=[[0,0],[1,0],[0,1]]
print(s.uniquePathsWithObstacles(obstacleGrid))
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).