#include <bits/stdc++.h>
using namespace std;
vector<int64_t> u, v;
int64_t max_(int64_t a, int64_t b) {
  if (a == u.size() || b == v.size()) return 0;
  if (u[a] > v[b])
    return max_(a, b + 1);
  else if (u[a] < v[b])
    return max_(a + 1, b);
  else
    return max_(a + 1, b + 1) + 1;
}
int main() {
  vector<int64_t> p, q;
  int64_t n, m, i, j, sum, a;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a;
    p.push_back(a);
  }
  for (j = 0; j < m; j++) {
    cin >> a;
    q.push_back(a);
  }
  for (i = 0; i < n; i++) {
    if (i == 0)
      sum = p[i];
    else
      sum += p[i];
    u.push_back(sum);
  }
  for (j = 0; j < m; j++) {
    if (j == 0)
      sum = q[j];
    else
      sum += q[j];
    v.push_back(sum);
  }
  cout << max_(0, 0);
}
