#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> m >> n;
  long long a[m], b[n], result = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long i = 0, j = 0, sum1 = a[0], sum2 = b[0];
  while (true) {
    if (sum1 == sum2) {
      result++;
      sum1 = sum2 = 0;
      i++;
      j++;
      sum1 += a[i];
      sum2 += b[j];
    } else if (sum1 > sum2) {
      j++;
      sum2 += b[j];
    } else if (sum2 > sum1) {
      i++;
      sum1 += a[i];
    }
    if (i >= m || j >= n) {
      break;
    }
  }
  cout << result << endl;
}
