#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
int getsum(long long int n) {
  int sum;
  for (sum = 0; n > 0; sum += n % 10, n /= 10)
    ;
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, temp, a;
  cin >> n >> m;
  temp = n;
  vector<long long int> arr1;
  ;
  vector<long long int> arr2;
  ;
  while (temp--) cin >> a, arr1.push_back(a);
  temp = m;
  while (temp--) cin >> a, arr2.push_back(a);
  long long int count = 0;
  long long int sumi = 0;
  long long int sumj = 0;
  for (int i = 0, j = 0; i < n, j < m;) {
    sumi += arr1[i];
    sumj += arr2[j];
    if (sumi == sumj)
      count++, sumi = 0, sumj = 0, i++, j++;
    else if (sumj > sumi)
      i++, arr2[j] = 0;
    else
      j++, arr1[i] = 0;
  }
  cout << count;
}
