#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int m, n, i, j, p1, p2, sum = 0, cnt = 0, sum2 = 0;
  cin >> n >> m;
  long long int a[n], b[m];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  p1 = 0;
  p2 = 0;
  if (n > m) {
    sum = 0;
    sum2 = 0;
    sum += a[p1];
    sum2 += b[p2];
    while (p1 <= n - 1 && p2 <= m - 1) {
      if (sum < sum2) {
        p1++;
        sum += a[p1];
      } else if (sum > sum2) {
        while (sum2 < sum) {
          p2++;
          sum2 += b[p2];
        }
        if (sum == sum2) {
          cnt++;
          sum = 0;
          p2++;
          sum2 = b[p2];
        }
      } else {
        cnt++;
        p2++;
        sum = 0;
        sum2 = b[p2];
      }
    }
    cout << cnt;
  } else {
    sum = 0;
    sum2 = 0;
    sum += b[p2];
    sum2 += a[p1];
    while (p1 <= n - 1 && p2 <= m - 1) {
      if (sum < sum2) {
        p2++;
        sum += b[p2];
      } else if (sum > sum2) {
        while (sum2 < sum) {
          p1++;
          sum2 += a[p1];
        }
        if (sum == sum2) {
          cnt++;
          sum = 0;
          p1++;
          sum2 = a[p1];
        }
      } else {
        cnt++;
        p1++;
        sum = 0;
        sum2 = a[p1];
      }
    }
    cout << cnt;
  }
  return 0;
}
