use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {n:i32,mut a:[i32;n]}
    let mut sum = 0;
    let mut b = 0;
    let mut tmp = 0;
    let mut i = 0;
    while i < a.len() {
        if i != 0 {
            b = a[i - 1];
            while b > a[i] + tmp {
                tmp += 1;
            }
            sum += tmp;
            a[i] += tmp;
            tmp = 0;
        }

        i += 1;
    }
    println!("{}", sum);
}
