#include <bits/stdc++.h>
long long mod = 1e9 + 7;
inline long long pwr(long long base, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n % 2 == 1) ans = ans * base;
    base = base * base;
    n /= 2;
  }
  return ans;
}
struct range {
  int l, h;
};
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int ct = 0;
  int as = a[0];
  int bs = b[0];
  int i = 1, j = 1;
  while (i < n || j < m) {
    if (as == bs) {
      ct++;
      as = a[i];
      bs = b[j];
      i++;
      j++;
    } else if (as < bs) {
      as += a[i];
      i++;
    } else if (bs < as) {
      bs += b[j];
      j++;
    }
  }
  ct++;
  cout << ct;
  return 0;
}
