#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  long long int a[200001];
  long long int max, min;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  max = min = a[0];
  int m = 0, t = 0;
  for (int i = 0; i < n; i++) {
    if (max <= a[i]) {
      max = a[i];
      t = i;
    }
  }
  long long int sum1 = 0;
  int max1 = a[0];
  for (int i = 0; i < t; i++) {
    if (max1 <= a[i]) {
      max1 = a[i];
    }
  }
  for (int i = 0; i < t; i++) {
    sum1 += (max1 - a[i]);
  }
  long long int sum2 = 0;
  for (int i = t; i < n; i++) {
    sum2 += (max - a[i]);
  }
  printf("%lld", sum2 + sum1);
}
