#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;
int main() {
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> A(n), B(m);
  for (int i = (0); i < (n); i++) cin >> A[i];
  for (int i = (0); i < (m); i++) cin >> B[i];
  int sum = 0;
  int sum1 = 0;
  int cnt = 0;
  int at = 0;
  for (int i = (0); i < (n); i++) {
    sum += A[i];
    while (sum > sum1) {
      sum1 += B[at];
      at++;
    }
    if (sum == sum1) {
      sum = 0;
      sum1 = 0;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
