#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const double PI = acos(-1.0);
const long double eps = 1e-6;
const int MAXN = 4e5 + 5;
const int N = 1e6;
const long long fix = 1e12;
int n, m;
queue<int> a, b;
int work() {
  scanf("%d%d", &n, &m);
  for (register int i = (1), I = (n) + 1; i < I; ++i) {
    int t;
    scanf("%d", &t);
    a.push(t);
  }
  for (register int i = (1), I = (m) + 1; i < I; ++i) {
    int t;
    scanf("%d", &t);
    b.push(t);
  }
  int ans = 1;
  int aa = a.front();
  a.pop();
  int bb = b.front();
  b.pop();
  while (!a.empty() || !b.empty()) {
    if (aa == bb) {
      ans++;
      aa = a.front(), a.pop();
      bb = b.front(), b.pop();
    } else if (aa > bb)
      bb += b.front(), b.pop();
    else
      aa += a.front(), a.pop();
  }
  return printf("%d\n", ans);
}
int main() {
  work();
  return 0;
}
