#include <bits/stdc++.h>
int const INF = 2e9;
int const MOD = 1000000007;
int const MAXN = 100010;
using namespace std;
int n, m, sum1, sum2, ans;
int a[MAXN], b[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < m; j++) cin >> b[j];
  int i = 1, j = 1;
  sum1 = a[0], sum2 = b[0];
  while (true) {
    if (sum1 < sum2)
      sum1 += a[i], i++;
    else if (sum2 < sum1)
      sum2 += b[j], j++;
    else {
      if (i == n && j == m) {
        ans++;
        break;
      } else
        sum1 = a[i], sum2 = b[j], i++, j++, ans++;
    }
  }
  cout << ans;
  return 0;
}
