#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 101235;
int a[N], b[N];
int main() {
  int n, m;
  cin >> 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 up = 0, down = 0;
  long long ans = 0;
  long long sumU = 0, sumD = 0;
  sumU += (long long)a[up++];
  sumD += (long long)b[down++];
  while (up < n && down < m) {
    if (sumU == sumD) {
      ans++;
      sumD = sumU = 0;
      sumU += (long long)a[up++];
      sumD += (long long)b[down++];
    } else if (sumU > sumD) {
      sumD += (long long)b[down++];
    } else if (sumU < sumD)
      sumU += (long long)a[up++];
  }
  if (up < n) {
    for (int i = up; i < n; i++) {
      sumU += (long long)a[i];
    }
    if (sumU == sumD) {
      ans++;
      sumD = sumU = 0;
    }
  }
  if (down < m) {
    for (int i = down; i < m; i++) {
      sumD += (long long)b[i];
    }
    if (sumU == sumD) {
      ans++;
      sumD = sumU = 0;
    }
  }
  if (sumD == sumU && sumD) ans++;
  cout << ans << endl;
  return 0;
}
