#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 j = 0; j < m; j++) cin >> b[j];
  long long int sum1 = a[0], sum2 = b[0];
  int i = 0, j = 0, ans = 0;
  while (i < n && j < m) {
    if (sum2 > sum1) {
      i++;
      sum1 += a[i];
    } else if (sum1 > sum2) {
      j++;
      sum2 += b[j];
    } else if (sum1 == sum2) {
      ans++;
      i++;
      j++;
      sum1 = a[i];
      sum2 = b[j];
    }
  }
  cout << ans << endl;
  return 0;
}
