#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, L = 20, MOD = 1e9 + 7, M = 10 + 10;
const long long inf = 1e18 + 10;
set<int> sa, sb;
set<int>::iterator it, io;
int psa[N], psb[N], a[N], b[N];
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    psa[i] = psa[i - 1] + a[i];
    sa.insert(psa[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    psb[i] = psb[i - 1] + b[i];
    sb.insert(psb[i]);
  }
  it = sa.begin();
  while (it != sa.end()) {
    int u = (*it);
    io = sb.lower_bound(u);
    if (io != sb.end() && (*io) == u) {
      ans++;
      it++;
    } else {
      it++;
    }
  }
  cout << ans << endl;
  return 0;
}
