#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  long long int a;
  cin >> a;
  vector<long long int> A(n);
  A[0] = a;
  for (long long int i = 1; i < n; ++i) {
    cin >> a;
    A[i] = a + A[i - 1];
  }
  long long int b;
  cin >> b;
  vector<long long int> B(m);
  B[0] = b;
  for (long long int i = 1; i < m; ++i) {
    cin >> b;
    B[i] = b + B[i - 1];
  }
  long long int now1 = 0, now2 = 0, count = 0;
  while (now1 < n && now2 < m) {
    if (A[now1] == B[now2] && now1 < n && now2 < m) {
      count++;
      now1++;
      now2++;
    } else if (A[now1] < B[now2] && now1 < n)
      now1++;
    else if (A[now1] > B[now2] && now2 < m)
      now2++;
  }
  cout << count;
  return 0;
}
