#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int tall[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &tall[i]);
  }
  int maxtall = tall[0];
  int sum = 0;
  for (int j = 0; j < n; j++) {
    if (tall[j] >= maxtall) {
      sum += tall[j] - maxtall;
      maxtall = tall[j];
    }
  }
  printf("%d\n", sum);
  return 0;
}
