#include <bits/stdc++.h>
using namespace std;
map<long long, bool> f;
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    sum += (long long)x;
    f[sum] = true;
  }
  int res = 0;
  sum = 0;
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    sum += x;
    if (f[sum]) res++;
  }
  cout << res;
}
