#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m;
int a[100010], b[100010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (int)0; i < (int)n; i++) scanf("%d", &a[i]);
  for (int i = (int)0; i < (int)m; i++) scanf("%d", &b[i]);
  int ans = 0, i = 0, j = 0, sa = -1, sb = -1;
  while (i < n || j < m) {
    if (sa == -1 && sb == -1) {
      if (a[i] > b[j]) {
        sa = a[i++];
        sb = 0;
      } else {
        sa = 0;
        sb = b[j++];
      }
    } else {
      if (sa > sb) {
        sb += b[j++];
      } else if (sa < sb) {
        sa += a[i++];
      }
    }
    if (sa == sb) {
      ans++;
      sa = -1;
      sb = -1;
    }
  }
  cout << ans << "\n";
  return 0;
}
