#include <bits/stdc++.h>
using namespace std;
inline long long Max(long long a, long long b) { return a > b ? a : b; }
inline long long Min(long long a, long long b) { return a < b ? a : b; }
inline long long read() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    write(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
void scan(int &x) {
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
long long sumx[100009];
long long sumy[100009];
int main() {
  int t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long x, y;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      sumx[i] += sumx[i - 1] + x;
    }
    for (int i = 1; i <= m; i++) {
      cin >> y;
      sumy[i] += sumy[i - 1] + y;
    }
    int idx = 0;
    int idy = 0;
    long long ans = 0;
    long long subx = 0;
    long long suby = 0;
    int i = 1;
    int j = 1;
    while (i != n + 1 && j != m + 1) {
      if ((sumx[i] - subx) > (sumy[j] - suby)) {
        j++;
      } else if ((sumy[j] - suby) > (sumx[i] - subx)) {
        i++;
      } else {
        subx = sumx[i];
        suby = sumy[j];
        ans++;
        idx = i;
        idy = j;
        i++;
        j++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
