#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int& i : a) cin >> i;
  for (int& i : b) cin >> i;
  for (int i = 1; i < n; i++) a[i] += a[i - 1];
  for (int j = 1; j < m; j++) b[j] += b[j - 1];
  bitset<1000010> s1, s2;
  for (int i : a) s1[i] = 1;
  for (int i : b) s2[i] = 1;
  s1 &= s2;
  cout << s1.count();
}
