#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec;
  sort(vec.begin(), vec.end());
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum = 0;
  for (int i = 1; i < N; i++) {
    sum += vec.at(i);
  }
  cout << sum - (N - 1) * vec.at(0) << endl;
}
