#include using namespace std; const int kMAX_N = 100010; int N; int a[kMAX_N]; void Solve() { int ans = 0, next_num = 1; for (int i = 0; i < N; i++) { if (a[i] < next_num) continue; ans += a[i] - next_num; next_num = a[i] + 1; } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } Solve(); return 0; }