#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000;
int n, m;
int ar1[maxn];
int ar2[maxn];
void read();
int main() {
  read();
  int i, j;
  int s1, s2;
  int file;
  i = j = s1 = s2 = file = 0;
  while (i < n) {
    if (s1 == 0)
      s1 += ar1[i++];
    else {
      if (s1 < s2)
        s1 += ar1[i++];
      else if (s1 == s2) {
        s1 = s2 = 0;
        file++;
      } else
        s2 += ar2[j++];
    }
  }
  if (s1 > 0) file++;
  cout << file << endl;
  return 0;
}
void read() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> ar1[i];
  for (int j = 0; j < m; j++) cin >> ar2[j];
}
