#include <bits/stdc++.h>
using namespace std;
bool vowel(char a) {
  a = toupper(a);
  if ((a == 'A') || (a == 'E') || (a == 'I') || (a == 'O') || (a == 'U'))
    return 1;
  return 0;
}
long long int n, m, q, a, b, c, sum = 0, cnt = 0;
long long int arr[1000055], brr[100005];
map<long long int, bool> mp;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < m; i++) cin >> brr[i];
  long long int sm1 = arr[0], sm2 = brr[0];
  int i = 1, j = 1;
  while (i <= n || j <= m) {
    while (sm1 < sm2 && i < n) {
      sm1 += arr[i++];
    }
    while (sm2 < sm1 && j < m) {
      sm2 += brr[j++];
    }
    if (sm1 == sm2 && sm1 != 0) {
      cnt++;
      sm1 = arr[i++], sm2 = brr[j++];
    }
  }
  cout << cnt << endl;
}
