#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<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, j;
  int c1 = 0, c2 = 0, c = 0;
  for (i = 0, j = 0; i < n && j < m;) {
    if (c1 == 0) c1 = a[i];
    if (c2 == 0) c2 = b[j];
    if (c1 == c2) {
      c++;
      i++;
      j++;
      c1 = 0;
      c2 = 0;
    } else if (c1 > c2) {
      j++;
      c2 += b[j];
    } else {
      i++;
      c1 += a[i];
    }
  }
  cout << c;
  return 0;
}
