#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], b[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < m; i++) scanf("%d", b + i);
  int ans = 0, tmpa = 0, tmpb = 0, i = 0, j = 0;
  while (i < n || j < m) {
    if (tmpa == tmpb && tmpa == 0)
      tmpa += a[i++], tmpb += b[j++];
    else {
      if (tmpa < tmpb)
        tmpa += a[i++];
      else if (tmpb < tmpa)
        tmpb += b[j++];
    }
    if (tmpa == tmpb) ans++, tmpa = tmpb = 0;
  }
  printf("%d\n", ans);
  return 0;
}
