#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
    }
    int ans = 0, tmp1 = 0, tmp2 = 0, cnt1 = 0, cnt2 = 0;
    while (1) {
      if (cnt1 == n && cnt2 == m) break;
      if (tmp1 < tmp2) {
        tmp1 += a[cnt1++];
      } else {
        tmp2 += b[cnt2++];
      }
      if (tmp1 == tmp2) {
        ++ans;
        tmp1 = 0;
        tmp2 = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
