#include <bits/stdc++.h>
using namespace std;
vector<long long> a, b;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    long long x;
    cin >> x;
    b.push_back(x);
  }
  reverse(b.begin(), b.end());
  int res = 0;
  long long suma = 0, sumb = 0;
  for (int i = 0; i < n; i++) {
    suma += a[i];
    if (suma == b.back()) {
      res++;
      suma = 0;
      b.pop_back();
    } else if (suma > b.back()) {
      long long x = b.back();
      b.pop_back();
      b[b.size() - 1] += x;
      suma -= a[i];
      i--;
    }
  }
  cout << res << endl;
}
