#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  deque<int> x, y;
  for (int i = 1; i <= n; ++i) {
    int p;
    cin >> p;
    x.push_back(p);
  }
  for (int i = 1; i <= m; ++i) {
    int p;
    cin >> p;
    y.push_back(p);
  }
  int ans = 0;
  while (!x.empty() && !y.empty()) {
    if (x.front() == y.front()) {
      x.pop_front();
      y.pop_front();
      ans++;
    } else if (x.front() < y.front()) {
      int z = x.front();
      x.pop_front();
      x.front() += z;
    } else {
      int z = y.front();
      y.pop_front();
      y.front() += z;
    }
  }
  cout << ans;
  return 0;
}
