#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> t1(n);
  vector<int> t2(m);
  for (int i = 0; i < (int)n; i++) {
    cin >> t1[i];
  }
  for (int i = 0; i < (int)m; i++) {
    cin >> t2[i];
  }
  int idx1 = 0, idx2 = 0;
  int sum1 = 0, sum2 = 0;
  int nb = 0;
  while (idx1 < n && idx2 < m) {
    if (sum1 == sum2 && (sum1 && sum2)) {
      sum1 = sum2 = 0;
      nb++;
    } else {
      if (sum1 <= sum2) {
        sum1 += t1[idx1];
        idx1++;
      } else {
        sum2 += t2[idx2];
        idx2++;
      }
    }
  }
  cout << nb + 1;
  return 0;
}
