#include <bits/stdc++.h>
using namespace std;
bool secdes(const pair<long long int, long long int>& a,
            const pair<long long int, long long int>& b) {
  if (a.second == b.second) {
    return a.first > b.first;
  } else {
    return a.second > b.second;
  }
}
bool sir(const pair<long long int, long long int>& a,
         const pair<long long int, long long int>& b) {
  if (a.first == b.first) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}
bool bysec(const pair<long long int, long long int>& a,
           const pair<long long int, long long int>& b) {
  if (a.second == b.second) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
const long long int no = 3e6 + 5;
const long long int modulo = 1e9 + 7;
const long long int N = 2001;
long long int ar[no + 10], br[no + 10], mat[N][N];
long long int dx[] = {-1, 0, 1, 0};
long long int dy[] = {0, 1, 0, -1};
char dc[] = {'L', 'D', 'R', 'U'};
long long int mul(long long int x, long long int y, long long int mod) {
  return ((x % mod) * (y % mod)) % mod;
}
long long int powwmod(long long int x, long long int y, long long int mod) {
  long long int res = 1;
  while (y) {
    if (y & 1) {
      y--;
      res = mul(res, x, mod);
      res %= mod;
    } else {
      y /= 2;
      x = mul(x, x, mod);
      x %= mod;
    }
  }
  return res % mod;
}
long long int poww(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y % 2) {
      y--;
      res = res * x;
    } else {
      y /= 2;
      x = x * x;
    }
  }
  return res;
}
long long int div(long long int x, long long int y, long long int mod) {
  return (x * powwmod(y, mod - 2, modulo)) % mod;
}
long long int add(long long int x, long long int y, long long int mod) {
  return (x % mod + y % mod) % mod;
}
bool comp(long long int x, long long int y) { return (x < y); }
long long int gcd(long long int x, long long int y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
  return (x * y) / gcd(x, y);
}
vector<long long int> adj[no];
long long int used[no], ans = 0, ans2 = 1, n = 0;
void solve() {
  long long int m = 0, a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, w = 0, k = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> ar[i];
  a = ar[0];
  for (long long int i = 1; i < n; i++) {
    ar[i] += b;
    if (a < ar[i]) {
      a = ar[i];
      continue;
    }
    b += a - ar[i];
  }
  cout << b;
}
inline void runn() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}

### Prompt

In Cpp, your task is to solve the following problem:

The Little Elephant loves sortings.

He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.

Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.

Output

In a single line print a single integer — the answer to the problem.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
1 2 3


Output

0


Input

3
3 2 1


Output

2


Input

4
7 4 1 47


Output

6

Note

In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.

In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).

In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool secdes(const pair<long long int, long long int>& a,
            const pair<long long int, long long int>& b) {
  if (a.second == b.second) {
    return a.first > b.first;
  } else {
    return a.second > b.second;
  }
}
bool sir(const pair<long long int, long long int>& a,
         const pair<long long int, long long int>& b) {
  if (a.first == b.first) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}
bool bysec(const pair<long long int, long long int>& a,
           const pair<long long int, long long int>& b) {
  if (a.second == b.second) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
const long long int no = 3e6 + 5;
const long long int modulo = 1e9 + 7;
const long long int N = 2001;
long long int ar[no + 10], br[no + 10], mat[N][N];
long long int dx[] = {-1, 0, 1, 0};
long long int dy[] = {0, 1, 0, -1};
char dc[] = {'L', 'D', 'R', 'U'};
long long int mul(long long int x, long long int y, long long int mod) {
  return ((x % mod) * (y % mod)) % mod;
}
long long int powwmod(long long int x, long long int y, long long int mod) {
  long long int res = 1;
  while (y) {
    if (y & 1) {
      y--;
      res = mul(res, x, mod);
      res %= mod;
    } else {
      y /= 2;
      x = mul(x, x, mod);
      x %= mod;
    }
  }
  return res % mod;
}
long long int poww(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y % 2) {
      y--;
      res = res * x;
    } else {
      y /= 2;
      x = x * x;
    }
  }
  return res;
}
long long int div(long long int x, long long int y, long long int mod) {
  return (x * powwmod(y, mod - 2, modulo)) % mod;
}
long long int add(long long int x, long long int y, long long int mod) {
  return (x % mod + y % mod) % mod;
}
bool comp(long long int x, long long int y) { return (x < y); }
long long int gcd(long long int x, long long int y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
  return (x * y) / gcd(x, y);
}
vector<long long int> adj[no];
long long int used[no], ans = 0, ans2 = 1, n = 0;
void solve() {
  long long int m = 0, a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, w = 0, k = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> ar[i];
  a = ar[0];
  for (long long int i = 1; i < n; i++) {
    ar[i] += b;
    if (a < ar[i]) {
      a = ar[i];
      continue;
    }
    b += a - ar[i];
  }
  cout << b;
}
inline void runn() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}

```