#include using namespace std; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } long long ans = 0; bool ok = true; for (int i = 0; i < N; i++){ if (A[i] <= N){ continue; } if (ok){ ans += A[i] - N - 1; ok = false; } ans++; if (i + 1 < N){ ans += A[i + 1] - A[i] - 1; } } cout << ans << '\n'; }