#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  b[0] = a[1] - a[0];
  for (int i = 1; i < n - 1; ++i) {
    b[i] = a[i + 1] - a[i] + b[0];
  }
  long long int s = 0;
  for (int i = 0; i < n; ++i) {
    s += b[i];
  }
  cout << s << endl;
  return 0;
}
