#include <bits/stdc++.h>
using namespace std;
int a[100050], b[100050];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= m; j++) cin >> b[j];
  int id1 = 1, id2 = 1;
  int ans = 0;
  int sum1 = a[1], sum2 = b[1];
  while (1) {
    if (id1 == n && id2 == m) break;
    if (sum1 > sum2) {
      id2++;
      sum2 += b[id2];
    } else if (sum1 < sum2) {
      id1++;
      sum1 += a[id1];
    } else {
      ans++;
      id1++, id2++;
      sum1 = a[id1];
      sum2 = b[id2];
    }
  }
  if (sum1 == sum2 && sum1 != 0) ans++;
  cout << ans << endl;
  return 0;
}
