#include<iostream>
using namespace std;
int main(){
 	int n;
  	cin>>n;
  	int * arr = new int [n];
  	for(int i=0;i<n;i++){
      cin>>arr[i];
    }
  	double diff =0;
  	for(int i=1;i<n;i++){
      if(a[i]<a[i-1]){
        diff = a[i-1] -a[i];
        a[i] = a[i-1];
      }
    }
    cout<<diff<<endl;
	return 0;
}