#include <bits/stdc++.h>
const int N = 100005;
using namespace std;
int n, m;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int l = 1, nowl = a[0], r = 1, nowr = b[0], ans = 0;
  while (l <= n && r <= m) {
    if (nowl == nowr) {
      ans++;
      nowl += a[l];
      nowr += b[r];
      l++, r++;
    } else if (nowl < nowr) {
      nowl += a[l];
      l++;
    } else if (nowl > nowr) {
      nowr += b[r];
      r++;
    }
  }
  cout << ans << '\n';
  return 0;
}
