#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> a(n+1), b(m+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];

    long long countZero = 0;

    auto process = [&](int i, int j) {
        long long sum = 0;
        while (i <= n && j <= m) {
            if (a[i] != b[j]) break;
            sum += a[i];
            if (sum == 0) countZero++;
            i++; j++;
        }
    };

    // Các đường chéo xuất phát từ a[1..n] với b[1]
    for (int i = 1; i <= n; i++)
        process(i, 1);

    // Các đường chéo xuất phát từ a[1] với b[2..m]
    for (int j = 2; j <= m; j++)
        process(1, j);

    cout << countZero;
    return 0;
}
