#include <bits/stdc++.h>
using namespace std;
long long in() {
  long long a;
  scanf("%lld", &a);
  return a;
}
double din() {
  double a;
  scanf("%lf", &a);
  return a;
}
long long bigmod(long long b, long long p, long long md) {
  if (p == 0) return 1;
  if (p % 2 == 1) {
    return ((b % md) * bigmod(b, p - 1, md)) % md;
  } else {
    long long y = bigmod(b, p / 2, md);
    return (y * y) % md;
  }
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long long n = in(), m = in();
  long long ar1[n + 5], ar2[m + 5];
  for (int i = 0; i < n; i++) ar1[i] = in();
  for (int i = 0; i < m; i++) ar2[i] = in();
  long long l = 0, r = 0, sum1 = 0, sum2 = 0, ans = 0;
  while ((l < n) && (r < m)) {
    sum1 += ar1[l];
    sum2 += ar2[r];
    if (sum1 == sum2) {
      sum1 = 0;
      sum2 = 0;
      r++;
      l++;
      ans++;
    } else if (sum1 > sum2) {
      r++;
      sum1 -= ar1[l];
      if (r == m) {
        ans = 0;
        break;
      }
    } else {
      sum2 -= ar2[r];
      l++;
      if (l == n) {
        ans = 0;
        break;
      }
    }
  }
  printf("%lld\n", ans);
}
