#include <bits/stdc++.h>
int main(void) {
  int N, i, ans = 0, mae = 1;
  scanf("%d", &N);
  int A[N];
  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    if (mae > A[i]) {
      ans += mae - A[i];
      A[i] += mae - A[i];
    }
    mae = A[i];
  }
  printf("%d", ans);
  return 0;
}
