#include <bits/stdc++.h>
using namespace std;
long n, m;
vector<long long> a, b;
int main() {
  cin >> n >> m;
  a.assign(n, 0);
  b.assign(m, 0);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> b[i];
  long i = 1, j = 1, res = 0;
  long long val1 = a[0];
  long long val2 = b[0];
  while (i + j <= m + n) {
    if (val1 == val2) {
      val1 = a[i];
      val2 = b[j];
      ++i;
      ++j;
      ++res;
    } else if (val1 < val2) {
      val1 += a[i];
      ++i;
    } else {
      val2 += b[j];
      ++j;
    }
  }
  cout << res;
}
