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