import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int nCount = 0; HashSet nSet = new HashSet<>(); for (int i = 0; i < n; i++) { nSet.add(nCount); nCount += sc.nextInt() + 1; } int mCount = 0; HashSet mSet = new HashSet<>(); for (int i = 0; i < m; i++) { mSet.add(mCount); mCount += sc.nextInt() + 1; } int[][] dp = new int[nCount+1][mCount+1]; for (int[] arr : dp) { Arrays.fill(arr, Integer.MAX_VALUE); } dp[0][0] = 0; for (int i = 0; i < nCount; i++) { for (int j = 0; j < mCount; j++) { if (nSet.contains(i) == mSet.contains(j)) { dp[i + 1][j + 1] = Math.min(dp[i + 1][j + 1], dp[i][j]); } dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j] + 1); dp[i][j + 1] = Math.min(dp[i][j + 1], dp[i][j] + 1); } } System.out.println(dp[nCount - 1][mCount - 1]); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }