#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
long long a[100010], b[100010];
int main() {
  scanf("%I64d %I64d", &n, &m);
  for (register int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    a[i] += a[i - 1];
  }
  for (register int j = 1; j <= m; ++j) {
    scanf("%I64d", &b[j]);
    b[j] += b[j - 1];
  }
  long long l = 1, r = 1, lstl = 0, lstr = 0;
  while (l <= n && r <= m) {
    while (a[l] - a[lstl] < b[r] - b[lstr]) ++l;
    if (a[l] - a[lstl] == b[r] - b[lstr] && l < n) {
      ++ans;
      lstl = l, lstr = r;
      ++l, ++r;
    }
    while (a[l] - a[lstl] > b[r] - b[lstr] && r < m) ++r;
    if (a[l] - a[lstl] == b[r] - b[lstr]) {
      ++ans;
      lstl = l, lstr = r;
      ++l, ++r;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
