#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ar[n];
  int br[m];
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < m; i++) cin >> br[i];
  int f = 0;
  int s = 0;
  int o, t;
  o = ar[f];
  t = br[s];
  int count = 0;
  while (f < n && s < m) {
    if (o == t) {
      count++;
      f++;
      s++;
      o = ar[f];
      t = br[s];
    } else if (o < t) {
      f++;
      o += ar[f];
    } else if (o > t) {
      s++;
      t += br[s];
    }
  }
  cout << count << endl;
  return 0;
}
