#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
int a[maxn], b[maxn];
int numa[maxn], numb[maxn];
int main() {
  while (cin >> n >> m) {
    memset(numa, 0, sizeof(numa));
    memset(numb, 0, sizeof(numb));
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) numa[i] = numa[i - 1] + a[i - 1];
    numa[n] = numa[n - 1] + a[n - 1];
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 1; i < m; i++) numb[i] = numb[i - 1] + b[i - 1];
    numb[m] = numb[m - 1] + b[m - 1];
    int la, ra, lb, rb;
    la = lb = 0;
    ra = rb = 1;
    int ans = 0;
    while (ra < n + 1 && rb < m + 1) {
      int num1 = numa[ra] - numa[la];
      int num2 = numb[rb] - numb[lb];
      if (num1 == num2) {
        ans++;
        la = ra;
        lb = rb;
        ra++;
        rb++;
      } else if (num1 > num2) {
        rb++;
      } else
        ra++;
    }
    cout << ans << endl;
  }
  return 0;
}
