#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
void read(long long &x) {
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
}
int main() {
  long long n, m;
  long long a[100005], b[100005];
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= m; i++) read(b[i]);
  long long i = 1, j = 1, sum1 = 0, sum2 = 0, ans = 0;
  while (i <= n || j <= m) {
    if (sum1 < sum2)
      sum1 += a[i++];
    else
      sum2 += b[j++];
    if (sum1 == sum2) {
      ans++;
      sum1 = 0;
      sum2 = 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
