N = int(input())
P1 = [0] + list(map(int, input().split()))
P2 = [0] + list(map(int, input().split()))

res1 = 0
for i in range(1, len(P1) - 1):
    if i == P1[i]:
        P1[i], P1[i + 1] = P1[i + 1], P1[i]
        res1 += 1

res2 = 0
for i in range(len(P2)-1, 1, -1):
    if i == P2[i]:
        P2[i], P2[i - 1] = P2[i - 1], P2[i]
        res2 += 1

print(min(res1, res2))

