#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1E6 + 7;
ll pre1[N];
ll pre2[N];
ll a[N];
ll b[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), pre1[i] = pre1[i - 1] + a[i];
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]), pre2[i] = pre2[i - 1] + b[i];
  int res = 0;
  int i = 1, j = 1;
  ll t1(a[1]), t2(b[1]);
  while (i <= n && j <= m) {
    if (t1 == t2) {
      i++;
      j++;
      res++;
      t1 = a[i];
      t2 = b[j];
    } else if (t1 < t2) {
      t1 += a[i + 1];
      i++;
    } else if (t1 > t2) {
      t2 += b[j + 1];
      j++;
    }
  }
  printf("%d\n", res);
  return 0;
}
