Scanf.(Array.(scanf " %d" @@ fun n ->
  init n (fun i -> scanf " %d" @@ fun v -> v)
  |> fold_left (fun (sum,prev) v ->
    if prev < v then sum + v - prev,v
    else sum,v
  ) (0,0)
  |> fst |> print_int))