#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int i = 0, j = 0, x = 0;
  int s1 = a[i], s2 = b[j];
  while (i < n && j < m) {
    if (s1 < s2) {
      i++;
      s1 += a[i];
    }
    if (s2 < s1) {
      j++;
      s2 += b[j];
    }
    if (s1 == s2) {
      i++;
      j++;
      s1 = a[i];
      s2 = b[j];
      x++;
    }
  }
  cout << x;
  return 0;
}
