#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  long long i = 0, j = 0;
  long long s1 = 0, s2 = 0;
  long long f = 0;
  while (i < n || j < m) {
    if (s1 == 0 && s2 == 0) {
      s1 += a[i];
      s2 += b[j];
      i++;
      j++;
    } else if (s1 == s2) {
      f++;
      s1 = s2 = 0;
    } else if (s1 > s2) {
      s2 += b[j];
      j++;
    } else if (s2 > s1) {
      s1 += a[i];
      i++;
    }
  }
  if (s1 == s2 && s1 != 0) f++;
  cout << f;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
