Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

cost = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    cost[0][0] = 1
else:
    cost[0][0] = 0

q = deque([[0, 0]])
moves = [[1, 0], [0, 1]]

while q:
    curr = q.popleft()
    curr_cost = cost[curr[0]][curr[1]]

    for m in moves:
        y, x = curr[0] + m[0], curr[1] + m[1]
        if y < h and x < w:
            if s[y][x] == "#":
                cost[y][x] = min(curr_cost + 1, cost[y][x])
            else:
                cost[y][x] = min(curr_cost, cost[y][x])
            q.append([y, x])
        else:
            continue

print(cost[-1][-1])

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

dp = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

moves = [[1, 0], [0, 1]]

for y in range(h):
    for x in range(w):
        for m in moves:
            ny, nx = y + m[0], x + m[1]
            if ny >= h or nx >= w:
                continue
            add = 0
            # .から#に突入する時だけカウントが増える
            if s[y][x] == "." and s[ny][nx] == "#":
                add = 1
            dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

cost = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    cost[0][0] = 1
else:
    cost[0][0] = 0

q = deque([[0, 0]])
moves = [[1, 0], [0, 1]]

while q:
    curr = q.popleft()
    curr_cost = cost[curr[0]][curr[1]]

    for m in moves:
        y, x = curr[0] + m[0], curr[1] + m[1]
        if y < h and x < w:
            if s[y][x] == "#":
                cost[y][x] = min(curr_cost + 1, cost[y][x])
            else:
                cost[y][x] = min(curr_cost, cost[y][x])
            q.append([y, x])
        else:
            continue

print(cost[-1][-1])

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

dp = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

moves = [[1, 0], [0, 1]]

for y in range(h):
    for x in range(w):
        for m in moves:
            ny, nx = y + m[0], x + m[1]
            if ny >= h or nx >= w:
                continue
            add = 0
            # .から#に突入する時だけカウントが増える
            if s[y][x] == "." and s[ny][nx] == "#":
                add = 1
            dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

cost = [[float("inf")] * w for _ in range(h)]

if s[0][0] == "#":
    cost[0][0] = 1
else:
    cost[0][0] = 0

q = deque([[0, 0]])
moves = [[1, 0], [0, 1]]

while q:
    curr = q.popleft()
    curr_cost = cost[curr[0]][curr[1]]

    for m in moves:
        if curr[0] + m[0] < h and curr[1] + m[1] < w:
            if s[curr[0] + m[0]][curr[1] + m[1]] == "#":
                cost[curr[0] + m[0]][curr[1] + m[1]] = min(curr_cost + 1, cost[curr[0] + m[0]][curr[1] + m[1]])
            else:
                cost[curr[0] + m[0]][curr[1] + m[1]] = min(curr_cost, cost[curr[0] + m[0]][curr[1] + m[1]])
            q.append([curr[0] + m[0], curr[1] + m[1]])
        else:
            continue

print(cost[-1][-1])

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

dp = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

moves = [[1, 0], [0, 1]]

for y in range(h):
    for x in range(w):
        for m in moves:
            ny, nx = y + m[0], x + m[1]
            if ny >= h or nx >= w:
                continue
            add = 0
            # .から#に突入する時だけカウントが増える
            if s[y][x] == "." and s[ny][nx] == "#":
                add = 1
            dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)

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