include[HTML_REMOVED]
using namespace std;
const int N=1e5+10;
int a[N];
int ans;
int main(){
int n;
scanf(“%d”,&n);
for(int i=1;i<=n;i++){
scanf(“%d”,&a[i]);
}
for(int i=2;i<=n;i++){
ans+=max(0,a[i]-a[i-1]);
}
printf("%d\n",ans);
return 0;
}