#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000];
int main() {
  int n, m, count = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (j < m && a[i] > b[j]) {
      while (j < m && a[i] > b[j]) {
        j++;
        b[j] += b[j - 1];
      }
      if (a[i] == b[j]) {
        count++;
        j++;
      } else {
        a[i + 1] += a[i];
      }
    } else if (a[i] == b[j]) {
      j++;
      count++;
    } else {
      a[i + 1] += a[i];
    }
  }
  cout << count << endl;
  return 0;
}
