#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> m >> n;
  vector<int> a;
  vector<int> b;
  for (int i = 0; i < m; i++) {
    int a_i;
    cin >> a_i;
    a.push_back(a_i);
  }
  for (int i = 0; i < n; i++) {
    int b_i;
    cin >> b_i;
    b.push_back(b_i);
  }
  int i = 1;
  int j = 1;
  int count = 0;
  int curr_sum_a = a[0];
  int curr_sum_b = b[0];
  for (; i < m + 1 && j < n + 1;) {
    if (curr_sum_b > curr_sum_a) {
      curr_sum_a += a[i];
      i++;
    } else if (curr_sum_a > curr_sum_b) {
      curr_sum_b += b[j];
      j++;
    } else if (curr_sum_a == curr_sum_b) {
      curr_sum_a = a[i];
      curr_sum_b = b[j];
      i++;
      j++;
      count++;
    }
  }
  cout << count;
}
