#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, m;
int a[MAXN], b[MAXN];
int main(void) {
  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;
  int posa = 0, posb = 0;
  long long suma = a[0], sumb = b[0];
  while (posa < n && posb < m) {
    while (posa < n && suma < sumb) suma += 1LL * a[++posa];
    while (posb < m && sumb < suma) sumb += 1LL * b[++posb];
    if (suma == sumb) {
      suma = a[++posa];
      sumb = b[++posb];
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
