#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int x[n], y[m];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> y[i];
  }
  int i = 0, j = 0;
  int files = 0;
  int s1 = x[0], s2 = y[0];
  while (i < n && j < m) {
    if (s1 == s2) {
      files++;
      i++;
      j++;
      if (i == n || j == m) {
        break;
      }
      s1 += x[i];
      s2 += y[j];
    } else if (s1 < s2) {
      i++;
      if (i == n || j == m) {
        break;
      }
      s1 += x[i];
    } else {
      j++;
      if (i == n || j == m) {
        break;
      }
      s2 += y[j];
    }
  }
  cout << files;
}
