#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long ar[n], br[m];
  long long i, j;
  for (i = 0; i < n; i++) cin >> ar[i];
  for (i = 0; i < m; i++) cin >> br[i];
  i = 0, j = 0;
  int smi = ar[0], smj = br[0], c = 0;
  while (i < n && j < m) {
    if (smj > smi) {
      i++;
      smi += ar[i];
    } else if (smj < smi) {
      j++;
      smj += br[j];
    } else if (smi == smj) {
      i++, j++;
      smi = ar[i];
      smj = br[j];
      c++;
    }
  }
  cout << c << endl;
  return 0;
}
