#include <bits/stdc++.h>
using namespace std;
int a[(int)1e5 + 10];
int b[(int)1e5 + 10];
int p[(int)1e5 + 10];
int p1[(int)1e5 + 10];
int sum(int l, int r) {
  if (r == -1) return 0;
  if (l == 0) return p[r];
  return (p[r] - p[l - 1]);
}
int sum2(int l, int r) {
  if (r == -1) return 0;
  if (l == 0) return p1[r];
  return (p1[r] - p1[l - 1]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
  }
  p[0] = b[0];
  p1[0] = a[0];
  int r = 0;
  int r1 = 0;
  int l = 0;
  for (int i = 1; i < m; i++) {
    p[i] = p[i - 1] + b[i];
  }
  for (int i = 1; i < n; i++) {
    p1[i] = p1[i - 1] + a[i];
  }
  int d = 0;
  int last = -1;
  while (l < n) {
    if (sum2(l, r) == sum(0, r1) - sum(0, last)) {
      l = r + 1;
      r++;
      last = r1;
      r1++;
      d++;
      continue;
    }
    if (sum2(l, r) < sum(0, r1) - sum(0, last)) {
      r++;
    } else
      r1++;
  }
  cout << d << endl;
  return 0;
}
