#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int first[maxn], second[maxn];
void ReadInput() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> first[i];
  for (int i = 1; i <= m; ++i) cin >> second[i];
}
void Solve() {
  int i = 1, j = 1;
  int curx = 0, cury = 0;
  int ans = 0;
  while (true) {
    if (i > n && j > m) {
      if (curx == cury) ++ans;
      break;
    }
    if (curx == cury) {
      if (curx > 0) ++ans;
      curx = first[i];
      cury = second[j];
      ++i;
      ++j;
    } else if (curx < cury) {
      curx += first[i];
      ++i;
    } else {
      cury += second[j];
      ++j;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ReadInput();
  Solve();
}
