#include <bits/stdc++.h>
using namespace std;
unsigned long long a, b;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> vn(n), vm(m);
  for (int i = 0; i < n; i++) cin >> vn[i];
  for (int i = 0; i < m; i++) cin >> vm[i];
  long long ans = 0;
  int j = 0;
  bool ok = 1;
  int i = 0;
  long long smi = vn[i], smj = vm[j];
  while (ok) {
    if (i == n || j == m) break;
    if (smi > smj) {
      smj += vm[++j];
    } else if (smj > smi) {
      smi += vn[++i];
    } else {
      ans++;
      i++, j++;
      if (i == n || j == m) break;
      smi = vn[i], smj = vm[j];
    }
  }
  cout << ans << endl;
  return 0;
}
