#include <bits/stdc++.h>
using namespace std;
inline int nxt() {
  int x;
  cin >> x;
  return x;
}
template <class T>
inline void LOG(T s) {}
const int INF = (int)1e9;
const int MODULO = (int)1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  int n, m;
  cin >> n >> m;
  unordered_map<int, bool> mm;
  int sum = 0;
  for (int i = 0; i < (int)n; i++) {
    int x = nxt();
    sum += x;
    mm[sum] = true;
  }
  sum = 0;
  int ans = 0;
  for (int i = 0; i < (int)m; i++) {
    int x = nxt();
    sum += x;
    ans += mm[sum] == true;
  }
  cout << ans << '\n';
  return 0;
}
