Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = []  # h, w
for i in range(h):
    s += [','.join(input()).split(',')]

cost = [[1 if s[0][0] == '#' else 0 for i in range(w)] for j in range(h)]

for i in range(1, h + w-1):
    for j in range(w if h < w else h):
        if i - j < w and j >= 0 and i - j >= 0:
            if j == 0:
                cost[j][i - j] = cost[j][i - j - 1]
            elif i - j == 0:
                cost[j][i - j] = cost[j - 1][i - j]
            else:
                cost[j][i - j] = cost[j - 1][i - j] if cost[j - 1][i -
                                                                   j] < cost[j][i - j - 1] else cost[j][i - j - 1]

            if s[j][i - j] == '#':
                cost[j][i - j] += 1

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

Fixed submission:
h, w = map(int, input().split())
s_list = []  # h, w
dp_dict = {}
for i in range(h):
    s = input()
    temp_list = []
    for temp in s:
        if temp == "#":
            temp_list.append(1)
        else:
            temp_list.append(0)
    s_list.append(temp_list)


def search(x, y, black):
    res = 0
    if (x, y, black) in dp_dict:
        return dp_dict[(x, y, black)]
    if x == w-1 and y == h-1:
        if s_list[y][x] == 1:
            if black:
                res = 0
            else:
                res = 1
        else:
            res = 0
    elif x == w-1:
        if s_list[y][x] == 1:
            if black:
                res = search(x, y+1, True)
            else:
                res = search(x, y+1, True)+1
        else:
            res = search(x, y+1, False)
    elif y == h-1:
        if s_list[y][x] == 1:
            if black:
                res = search(x+1, y, True)
            else:
                res = search(x+1, y, True)+1
        else:
            res = search(x+1, y, False)
    else:
        if s_list[y][x] == 1:
            if black:
                res = min([search(x+1, y, True), search(x, y+1, True)])
            else:
                res = min([search(x+1, y, True), search(x, y+1, True)])+1
        else:
            res = min([search(x+1, y, False), search(x, y+1, False)])
    dp_dict[(x, y, black)] = res
    return res


print(search(0, 0, False))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = list(map(int, input().split(" ")))
s_list = []
ans_list = []
for i in range(H):
    s = input()
    temp_list = []
    for temp in s:
        if temp == "#":
            temp_list.append(1)
        else:
            temp_list.append(0)
    s_list.append(temp_list)


def a(now_x, now_y, black, black_count, sum_count):
    global s_list, ans_list
    if now_x == W-1 and now_y == H-1:
        if black_count > 0:
            sum_count += black_count
        elif s_list[now_y][now_x] == 1:
            sum_count += 1
        ans_list.append(sum_count)
        return
    if s_list[now_y][now_x] == 1:
        black = True
        if now_x < W-1:
            a(now_x+1, now_y, black, black_count+1, sum_count)
        if now_y < H-1:
            a(now_x, now_y+1, black, black_count+1, sum_count)
    else:
        if black:
            sum_count += black_count
        black = False
        black_count = 0
        if now_x < W-1:
            a(now_x+1, now_y, black, black_count, sum_count)
        if now_y < H-1:
            a(now_x, now_y+1, black, black_count, sum_count)


a(0, 0, False, 0, 0)
print(min(ans_list))


Fixed submission:
h, w = map(int, input().split())
s_list = []  # h, w
dp_dict = {}
for i in range(h):
    s = input()
    temp_list = []
    for temp in s:
        if temp == "#":
            temp_list.append(1)
        else:
            temp_list.append(0)
    s_list.append(temp_list)


def search(x, y, black):
    res = 0
    if (x, y, black) in dp_dict:
        return dp_dict[(x, y, black)]
    if x == w-1 and y == h-1:
        if s_list[y][x] == 1:
            if black:
                res = 0
            else:
                res = 1
        else:
            res = 0
    elif x == w-1:
        if s_list[y][x] == 1:
            if black:
                res = search(x, y+1, True)
            else:
                res = search(x, y+1, True)+1
        else:
            res = search(x, y+1, False)
    elif y == h-1:
        if s_list[y][x] == 1:
            if black:
                res = search(x+1, y, True)
            else:
                res = search(x+1, y, True)+1
        else:
            res = search(x+1, y, False)
    else:
        if s_list[y][x] == 1:
            if black:
                res = min([search(x+1, y, True), search(x, y+1, True)])
            else:
                res = min([search(x+1, y, True), search(x, y+1, True)])+1
        else:
            res = min([search(x+1, y, False), search(x, y+1, False)])
    dp_dict[(x, y, black)] = res
    return res


print(search(0, 0, False))