Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

cnt = 0
#solve
def dfs(i, j, score, lc):
    if lc == '.' and g[i][j] == '#':
        score += 1
    dp[i][j] = min(dp[i][j], score)

    if i+1 < H:
        dfs(i+1, j, score, g[i][j])
    if j+1 < W:
        dfs(i, j+1, score, g[i][j])        

dfs(0, 0, 0, '.')
print(dp[H-1][W-1])

Fixed submission:
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

dp[0][0] = 1 if g[0][0] == '#' else 0
d = ([0,1], [1,0])
for ix in range(H):
    for jx in range(W):
        for dx,dy in d:
            ni = ix + dx
            nj = jx + dy
            if ni >= H or nj >= W:
                continue
            add = 0
            if g[ix][jx] == '.' and g[ni][nj] == '#':
                add += 1
            dp[ni][nj] = min(dp[ni][nj], dp[ix][jx] + add)


print(dp[H-1][W-1])

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

cnt = 0
#solve
def dfs(i, j, score, lc):
    
    if i < H and i >= 0 and j < W and j >= 0:
        if lc == '.' and g[i][j] == '#':
            score += 1
        dp[i][j] = min(dp[i][j], score)

        if i+1 < H:
            dfs(i+1, j, score, g[i][j])
        if j+1 < W:
            dfs(i, j+1, score, g[i][j])        

dfs(0, 0, 0, '.')
print(dp[H-1][W-1])

Fixed submission:
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

dp[0][0] = 1 if g[0][0] == '#' else 0
d = ([0,1], [1,0])
for ix in range(H):
    for jx in range(W):
        for dx,dy in d:
            ni = ix + dx
            nj = jx + dy
            if ni >= H or nj >= W:
                continue
            add = 0
            if g[ix][jx] == '.' and g[ni][nj] == '#':
                add += 1
            dp[ni][nj] = min(dp[ni][nj], dp[ix][jx] + add)


print(dp[H-1][W-1])

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

#solve
def dfs(i, j, score, lc):
    if i < H and i >= 0 and j < W and j >= 0:
        if lc == '.' and g[i][j] == '#':
            score += 1
        dp[i][j] = min(dp[i][j], score)

        dfs(i+1, j, score, g[i][j])
        dfs(i, j+1, score, g[i][j])        
    
dfs(0, 0, 0, '.')
print(dp[H-1][W-1])

Fixed submission:
H,W = map(int, input().split())
g = []
for _ in range(H):
    g.append(list(input()))

dp = [[10**9 for _ in range(W)] for __ in range(H)]

dp[0][0] = 1 if g[0][0] == '#' else 0
d = ([0,1], [1,0])
for ix in range(H):
    for jx in range(W):
        for dx,dy in d:
            ni = ix + dx
            nj = jx + dy
            if ni >= H or nj >= W:
                continue
            add = 0
            if g[ix][jx] == '.' and g[ni][nj] == '#':
                add += 1
            dp[ni][nj] = min(dp[ni][nj], dp[ix][jx] + add)


print(dp[H-1][W-1])