#include <bits/stdc++.h>
int main() {
  int n, m, i, j = 0, s1 = 0, s2 = 0, c = 0;
  scanf("%d%d", &n, &m);
  int x[n], y[m];
  for (i = 0; i < n; i++) scanf("%d", &x[i]);
  for (i = 0; i < m; i++) scanf("%d", &y[i]);
  for (i = 0; i < n; i++) {
    s1 += x[i];
    while (s1 > s2 && j < m) {
      s2 += y[j++];
    }
    if (s1 == s2) {
      c++;
      s1 = s2 = 0;
    }
  }
  printf("%d", c);
}
