#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int oo = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T lowbit(T n) {
  return (n ^ (n - 1)) & n;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <class T>
inline T gcd(T a, T b) {
  T c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
template <class T>
inline T mabs(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;
const int N = (int)1e5 + 111;
const int MOD = (int)1e9 + 7;
int x[N], y[N];
inline int solve(int testnum) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < int(n); i++) scanf("%d", x + i);
  for (int i = (0); i < int(m); i++) scanf("%d", y + i);
  long long totx = 0, toty = 0;
  int res = 0, px = 0, py = 0;
  while (px < n && py < m) {
    if (totx <= toty)
      totx += x[px++];
    else
      toty += y[py++];
    if (totx == toty) {
      ++res;
    }
  }
  if (py < m) {
    if (totx == toty + accumulate(y + py, y + m, 0)) ++res;
  } else if (px < n) {
    if (totx + accumulate(x + px, x + n, 0) == toty) ++res;
  }
  printf("%d\n", res);
  return 0;
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  int t = 1;
  if (argc > 1) t = atoi(argv[1]);
  for (int _t = (1); _t < int(t + 1); _t++) {
    int ret = ::solve(_t);
    if (ret == -1) {
      cerr << "Failed test #" << _t << endl;
      break;
    }
    cerr << "Solved test #" << _t << endl;
  }
  return 0;
}
