#include <bits/stdc++.h>
using namespace std;
vector<long long> lol1;
vector<long long> lol2;
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    lol1.push_back(x);
  }
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    lol2.push_back(x);
  }
  long long s1 = lol1[0], s2 = lol2[0];
  long long x = 1, y = 1;
  long long ans = 0;
  while (true) {
    if (s1 < s2) {
      if (x == n) break;
      s1 += lol1[x];
      x++;
    }
    if (s2 < s1) {
      if (y == m) break;
      s2 += lol2[y];
      y++;
    }
    if (s1 == s2) {
      ans++;
      s1 = lol1[x];
      s2 = lol2[y];
      x++;
      y++;
      if (x > n && y > m) break;
    }
  }
  cout << ans << endl;
}
