Buggy python submission (verdict: Time Limit Exceeded):
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()
vals = [[float('inf')]*w for _ in range(h)]

if s[0][0] == '#':
    q.put([0, 0, 1])
else:
    q.put([0, 0, 0])

while not q.empty():
    a = q.get()
    if a[0] == h-1 and a[1] == w-1:
        ans = min(ans, a[2])
        
    if a[0]+1 < h:
        if s[a[0]+1][a[1]] == '.':
            q.put([a[0]+1, a[1], a[2]])
            vals[a[0]+1][a[1]] = a[2]
        elif vals[a[0]][a[1]]+1 <= vals[a[0]+1][a[1]]:
            q.put([a[0]+1, a[1], a[2]+1])
            vals[a[0]+1][a[1]] = a[2]+1

    if a[1]+1 < w:
        if s[a[0]][a[1]+1] == '.':
            q.put([a[0], a[1]+1, a[2]])
        elif vals[a[0]][a[1]]+1 <= vals[a[0]][a[1]+1]:
            q.put([a[0], a[1]+1, a[2]+1])
            vals[a[0]][a[1]+1] = a[2]+1
print(ans)


Fixed submission:
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()
vals = [[float('inf')]*w for _ in range(h)]
vals[0][0] = 0
q.put([0, 0])

while not q.empty():
    a = q.get()
    for i, j in ((1, 0), (0, 1)):
        x, y = a[0]+i, a[1]+j
        if 0 <= x < h and 0 <= y < w:
            if s[x][y] == '#' and s[a[0]][a[1]] == '.':
                if vals[x][y] > vals[a[0]][a[1]]+1:
                    vals[x][y] = vals[a[0]][a[1]]+1
                    q.put([x, y])
            elif vals[x][y] > vals[a[0]][a[1]]:
                vals[x][y] = vals[a[0]][a[1]]
                q.put([x, y])
ans = vals[-1][-1]
if s[0][0] == '#':
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()

if s[0][0] == '#':
    q.put([0, 0, 1])
else:
    q.put([0, 0, 0])

while not q.empty():
    a = q.get()
    if ans <= a[2]:
        continue
    
    if a[0] == h-1 and a[1] == w-1:
        ans = min(ans, a[2])
        
    if a[0]+1 < h and a[1]+1 < w:
        if s[a[0]+1][a[1]] == '.' and s[a[0]][a[1]+1] == '.':
            q.put([a[0]+1, a[1], a[2]])
            q.put([a[0], a[1]+1, a[2]])
        elif s[a[0]+1][a[1]] == '.' and s[a[0]][a[1]+1] == '#':
            q.put([a[0]+1, a[1], a[2]])
        elif s[a[0]+1][a[1]] == '#' and s[a[0]][a[1]+1] == '.':
            q.put([a[0], a[1]+1, a[2]])
        else:
            q.put([a[0]+1, a[1], a[2]+1])
            q.put([a[0], a[1]+1, a[2]+1])
    elif a[0]+1 < h:
        if s[a[0]+1][a[1]] == '.':
            q.put([a[0]+1, a[1], a[2]])
        else:
            q.put([a[0]+1, a[1], a[2]+1])
    elif a[1]+1 < w:
        if s[a[0]][a[1]+1] == '.':
            q.put([a[0], a[1]+1, a[2]])
        else:
            q.put([a[0], a[1]+1, a[2]+1])
        
print(ans)


Fixed submission:
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()
vals = [[float('inf')]*w for _ in range(h)]
vals[0][0] = 0
q.put([0, 0])

while not q.empty():
    a = q.get()
    for i, j in ((1, 0), (0, 1)):
        x, y = a[0]+i, a[1]+j
        if 0 <= x < h and 0 <= y < w:
            if s[x][y] == '#' and s[a[0]][a[1]] == '.':
                if vals[x][y] > vals[a[0]][a[1]]+1:
                    vals[x][y] = vals[a[0]][a[1]]+1
                    q.put([x, y])
            elif vals[x][y] > vals[a[0]][a[1]]:
                vals[x][y] = vals[a[0]][a[1]]
                q.put([x, y])
ans = vals[-1][-1]
if s[0][0] == '#':
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()

if s[0][0] == '#':
    q.put([0, 0, 1])
else:
    q.put([0, 0, 0])

while not q.empty():
    a = q.get()
    if ans <= a[2]:
        continue
    
    if a[0] == h-1 and a[1] == w-1:
        ans = min(ans, a[2])
        
    if a[0]+1 < h:
        if s[a[0]+1][a[1]] == '#':
            q.put([a[0]+1, a[1], a[2]+1])
        else:
            q.put([a[0]+1, a[1], a[2]])

    if a[1]+1 < w:
        if s[a[0]][a[1]+1] == '#':
            q.put([a[0], a[1]+1, a[2]+1])
        else:
            q.put([a[0], a[1]+1, a[2]])
print(ans)


Fixed submission:
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()
vals = [[float('inf')]*w for _ in range(h)]
vals[0][0] = 0
q.put([0, 0])

while not q.empty():
    a = q.get()
    for i, j in ((1, 0), (0, 1)):
        x, y = a[0]+i, a[1]+j
        if 0 <= x < h and 0 <= y < w:
            if s[x][y] == '#' and s[a[0]][a[1]] == '.':
                if vals[x][y] > vals[a[0]][a[1]]+1:
                    vals[x][y] = vals[a[0]][a[1]]+1
                    q.put([x, y])
            elif vals[x][y] > vals[a[0]][a[1]]:
                vals[x][y] = vals[a[0]][a[1]]
                q.put([x, y])
ans = vals[-1][-1]
if s[0][0] == '#':
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = []
q = queue.Queue()

if s[0][0] == '#':
    q.put([0, 0, 1])
else:
    q.put([0, 0, 0])

while not q.empty():
    a = q.get()
    if a[0] == h-1 and a[1] == w-1:
        ans.append(a[2])

    if a[0]+1 < h:
        if s[a[0]+1][a[1]] == '#':
            q.put([a[0]+1, a[1], a[2]+1])
        elif s[a[0]+1][a[1]] != '#':
            q.put([a[0]+1, a[1], a[2]])

    if a[1]+1 < w:
        if s[a[0]][a[1]+1] == '#':
            q.put([a[0], a[1]+1, a[2]+1])
        elif s[a[0]][a[1]+1] != '#':
            q.put([a[0], a[1]+1, a[2]])
print(min(ans))


Fixed submission:
import queue
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = float('inf')
q = queue.Queue()
vals = [[float('inf')]*w for _ in range(h)]
vals[0][0] = 0
q.put([0, 0])

while not q.empty():
    a = q.get()
    for i, j in ((1, 0), (0, 1)):
        x, y = a[0]+i, a[1]+j
        if 0 <= x < h and 0 <= y < w:
            if s[x][y] == '#' and s[a[0]][a[1]] == '.':
                if vals[x][y] > vals[a[0]][a[1]]+1:
                    vals[x][y] = vals[a[0]][a[1]]+1
                    q.put([x, y])
            elif vals[x][y] > vals[a[0]][a[1]]:
                vals[x][y] = vals[a[0]][a[1]]
                q.put([x, y])
ans = vals[-1][-1]
if s[0][0] == '#':
    ans += 1

print(ans)