#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long nCr(long long n, long long r) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1];
  return C[r];
}
long long M(long long a) { return (a % (1000000007LL)); }
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> A(n);
  vector<int> B(m);
  for (long long i = 0; i < (long long)(n); ++i) cin >> A[i];
  for (long long i = 0; i < (long long)(m); ++i) cin >> B[i];
  long long i = 0, j = 0;
  long long count = 0;
  long long sum1 = A[0], sum2 = B[0];
  while (i < n && j < m) {
    if (sum1 == sum2) {
      count++;
      i++;
      j++;
      sum1 = A[i];
      sum2 = B[j];
    } else if (sum1 > sum2) {
      sum2 += B[++j];
    } else if (sum1 < sum2) {
      sum1 += A[++i];
    }
  }
  cout << count << endl;
  return 0;
}
