#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, n, t = 0, l = 0, k = 0, cnt = 0, mini = 999999,
                     maxi = -999999999, ans = 0;
  long long m;
  cin >> n >> m;
  long long x[n], y[m];
  for (i = 0; i < n; i++) cin >> x[i];
  for (i = 0; i < m; i++) cin >> y[i];
  long long sumx = 0, sumy = 0;
  i = 0, j = 0;
  sumx += x[i];
  sumy += y[j];
  while (i < n || j < m) {
    if (sumx < sumy && i < n - 1) {
      i++;
      sumx += x[i];
    } else if (sumx > sumy && j < m - 1) {
      j++;
      sumy += y[j];
    } else if (sumx == sumy && i < n && j < m) {
      i++, j++;
      if (sumx != 0) cnt++;
      sumx = 0, sumy = 0;
      if (i < n) sumx += x[i];
      if (j < m) sumy += y[j];
    }
  }
  return cout << cnt, 0;
  ;
  return 0;
}
