#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
int n1, n2;
int q1[N], q2[N];
int cnt;
int main() {
  scanf("%d %d", &n1, &n2);
  for (int i = 1; i <= n1; i++) scanf("%d", &q1[i]);
  for (int i = 1; i <= n2; i++) scanf("%d", &q2[i]);
  int x = 1, y = 1;
  int xn = 0, yn = 0;
  while (x <= n1 || y <= n2) {
    xn = q1[x], yn = q2[y];
    while (xn != yn && xn != 0) {
      if (xn > yn)
        yn += q2[++y];
      else
        xn += q1[++x];
    }
    cnt++;
    x++, y++;
  }
  cout << cnt << endl;
  return 0;
}
