#include <bits/stdc++.h>
using namespace std;
vector<int> ReadVector(int size) {
  vector<int> vec(size);
  for (auto &elem : vec) {
    cin >> elem;
  }
  return vec;
}
int main() {
  int n, m;
  cin >> n >> m;
  auto a = ReadVector(n);
  auto b = ReadVector(m);
  auto ia = 0;
  auto suma = 0;
  auto ib = 0;
  auto sumb = 0;
  auto count = 0;
  while (ia <= n && ib <= m) {
    if (suma == sumb && suma != 0) {
      count += 1;
      suma = a[ia++];
      sumb = b[ib++];
    } else if (ia >= n) {
      sumb += b[ib++];
    } else if (ib >= m) {
      suma += a[ia++];
    } else if (suma > sumb) {
      sumb += b[ib++];
    } else {
      suma += a[ia++];
    }
  }
  cout << count << "\n";
  return 0;
}
