#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[n], b[m];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  int sum = 0, l1 = 1, l2 = 1;
  long long t1 = a[0], t2 = b[0];
  while (l1 <= n && l2 <= m) {
    while (t1 < t2 && l1 < n) {
      t1 += a[l1];
      l1++;
    }
    while (t2 < t1 && l2 < m) {
      t2 += b[l2];
      l2++;
    }
    if (t1 == t2) {
      sum++;
      t1 = a[l1++];
      t2 = b[l2++];
    }
  }
  printf("%d\n", sum);
}
