#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void boost() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  boost();
  int n, m;
  cin >> n >> m;
  long long a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int x = 1, y = 0;
  long long suma = a[0], sumb = 0;
  int ans = 0;
  while (x < n && y < m) {
    if (suma > sumb) {
      sumb += b[y++];
    } else if (suma < sumb) {
      suma += a[x++];
    }
    if (suma == sumb) {
      suma = a[x++];
      sumb = 0;
      ans++;
    }
  }
  if (x != n - 1 || y != m - 1)
    cout << ans + 1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
