#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<int> a, b;
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (0); i < (m); ++i) cin >> b[i];
  int ans = 0, i = 0, j = 0, sa, sb;
  while (i < n && j < m) {
    sa = a[i++];
    sb = b[j++];
    while (i < n && j < m && sa != sb) {
      while (sa < sb) sa += a[i++];
      while (sb < sa) sb += b[j++];
    }
    ++ans;
  }
  cout << ans << endl;
}
