Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[change(s) for s in input()] for i in range(h)]

    cnt = 200
    for move in itertools.product(range(0, 2), repeat=h + w - 2):

        if sum(move) != h - 1:
            continue

        x, y, z = 0, 0, board[0][0]
        temp_root = [(x, y, z)]
        change_cnt = 0
        if board[y][x] == 1:
            change_cnt += 1

        x_cnt = 0
        y_cnt = 0
        sum_x_cnt = 1
        sum_y_cnt = 1
        for hko in move:
            now_z = 0
            # 0なら横移動
            if hko == 0:
                x += 1
                now_z = board[y][x]
                if now_z == 1:
                    x_cnt += 1
                else:
                    x_cnt = 0
                y_cnt = 0
            else:
                y += 1
                now_z = board[y][x]
                if now_z == 1:
                    y_cnt += 1
                else:
                    y_cnt = 0
                x_cnt = 0

            sum_x_cnt = max(sum_x_cnt, x_cnt)
            sum_y_cnt = max(sum_y_cnt, y_cnt)
            z += now_z
            temp_root.append((x, y, z))

        cnt = min(cnt, z - sum_x_cnt - sum_y_cnt + 2)

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[s for s in input()] for i in range(h)]

    cnt = 200
    dp = [[200] * w for i in range(h)]

    for i_row, row in enumerate(dp):
        for i_col, col in enumerate(row):
            if i_row == 0 and i_col == 0:
                dp[i_row][i_col] = change(board[i_row][i_col])
                continue

            if i_row >= 1:
                if board[i_row][i_col] == '#' and board[i_row - 1][i_col] == '.':
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col], dp[i_row][i_col])

            if i_col >= 1:
                if board[i_row][i_col] == '#' and board[i_row][i_col - 1] == '.':
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1], dp[i_row][i_col])

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


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[change(s) for s in input()] for i in range(h)]

    cnt = 200
    for move in itertools.product(range(0, 2), repeat=h + w - 2):

        if sum(move) != h - 1:
            continue

        x, y = (0, 0)
        temp_root = [(x, y, board[y][x])]
        change_cnt = 0
        if board[y][x] == 1:
            change_cnt += 1

        for hko in move:
            # 0なら横移動
            if hko == 0:
                x += 1
            else:
                y += 1

            # temp_root.append((x, y, board[y][x]))

            if board[y][x] == 1:
                change_cnt += 1

        cnt = min(cnt, change_cnt)

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[s for s in input()] for i in range(h)]

    cnt = 200
    dp = [[200] * w for i in range(h)]

    for i_row, row in enumerate(dp):
        for i_col, col in enumerate(row):
            if i_row == 0 and i_col == 0:
                dp[i_row][i_col] = change(board[i_row][i_col])
                continue

            if i_row >= 1:
                if board[i_row][i_col] == '#' and board[i_row - 1][i_col] == '.':
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col], dp[i_row][i_col])

            if i_col >= 1:
                if board[i_row][i_col] == '#' and board[i_row][i_col - 1] == '.':
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1], dp[i_row][i_col])

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


if __name__ == '__main__':
    main()