#include<bits/stdc++.h>
using namespace std;

int main(){
  int N;
  long long count;
  cin >> N;
  vector<int> a(N);
  count = 0;
  
  for(int i = 0;i < N;i++){
     cin >> a.at(i);
    if(i > 0){
      if(a.at(i-1) > a.at(i)){
        count += a.at(i-1) - a.at(i);
        a.at(i) = a.at(i-1);
      }
    }
  }
  cout << count << endl;
  
}
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll a,b; cin >> a >> b;
  cout << max(a*b,max(a+b,a-b)) << endl;
}