N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def f(data):
    res = []
    for a in data:
        res.append(0)
        res += [1] * a
    return res


A = f(A)
B = f(B)
N = len(A)
M = len(B)

INF = 10**18
dp = [[INF]*(M+1) for _ in range(N+1)]
dp[0][0] = 0
for i, ai in enumerate(A, start=1):
    for j, bj in enumerate(B, start=1):
        cost = int(ai != bj)
        dp[i][j] = min(
            dp[i][j], dp[i-1][j-1]+cost, dp[i][j-1]+1, dp[i-1][j]+1
        )

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