#include <iostream>
#include <vector>

using namespace std;

// Fast I/O Macro
void Mbappe() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void solve() {
    int n;
    long long d;
    if (!(cin >> n >> d)) return;
    
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    // Function to check if we can achieve a final height of 'mid'
    auto check = [&](long long mid) {
        long long req = mid;
        // Moving backwards
        for (int i = n - 1; i >= 0; i--) {
            if (req >= a[i]) {
                req += a[i];
            }
        }
        return req <= d; // Can we do this within our budget?
    };

    long long low = 0, high = d, ans = 0;
    
    // Binary Search on the final height
    while (low <= high) {
        long long mid = low + (high - low) / 2;
        if (check(mid)) {
            ans = mid;       // If valid, save it and try for a higher height
            low = mid + 1;
        } else {
            high = mid - 1;  // If not valid, we need to aim lower
        }
    }
    
    cout << ans << "\n";
}

int main() {
    Mbappe();
    // Vamoooos__ACCPTED
    int t = 1; 
    // cin >> t; // Uncomment if the problem adds multiple test cases later
    while (t--) {
        solve();
    }
    return 0;
}