#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, k;
  cin >> n >> m;
  long long a[n + 5];
  long long b[m + 5];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  if (n >= m)
    k = n;
  else
    k = m;
  long long sum = a[0], sum1 = 0;
  int j = 0, c = 0;
  for (int i = 1; i < n || j < m;) {
    if (sum < sum1) {
      sum += a[i];
      i++;
    } else if (sum > sum1) {
      sum1 += b[j];
      j++;
    }
    if (sum == sum1) {
      sum = a[i++];
      sum1 = 0;
      c++;
    }
  }
  cout << c << endl;
  return 0;
}
