#include <bits/stdc++.h>
using namespace std;
int main() {
  int n0;
  long long t = 0;
  cin >> n0;
  const int n = n0;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n - 1; i++)
    if (arr[n + 1] < arr[n])
      t = t + arr[n + 1] - arr[n];
    else
      NULL;
  cout << t;
  return 0;
}
