#include <bits/stdc++.h>
using namespace std;
int n, m;
long long int arr[100009];
long long int arr1[100009];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &arr1[i]);
  }
  long long int a = 0;
  long long int b = 0;
  int cnt = 0;
  int i = 1;
  int j = 1;
  while (1) {
    if (a == 0 and b == 0) {
      a = a + arr[i];
      i++;
      b = b + arr1[j];
      j++;
    }
    if (a == b and a != 0) {
      cnt++;
      a = 0;
      b = 0;
      if (i > n and j > m) break;
    } else if (a < b) {
      a = a + arr[i];
      i++;
    } else {
      b = b + arr1[j];
      j++;
    }
  }
  printf("%d", cnt), printf("\n");
  return 0;
}
