#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 10;
const int eps = 1e-14;
const int mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn], b[maxn];
int sum1, sum2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int l = 1;
  int sum1 = 0, sum2 = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    sum1 += a[i];
    while (sum1 > sum2) {
      sum2 += b[l];
      l++;
    }
    if (sum1 == sum2) {
      ans++;
      sum2 = 0;
      sum1 = 0;
    }
  }
  cout << ans << endl;
}
