#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
long long a[100010], b[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
  }
  int l1 = 1;
  int l2 = 1;
  long long sum1 = a[1];
  long long sum2 = b[1];
  while (l1 <= n && l2 <= m) {
    if (sum1 == sum2) {
      ans++;
      l1++;
      l2++;
      sum1 = a[l1];
      sum2 = b[l2];
    } else if (sum1 > sum2) {
      l2++;
      sum2 += b[l2];
    } else {
      l1++;
      sum1 += a[l1];
    }
  }
  cout << ans << endl;
  return 0;
}
