#include <bits/stdc++.h>
namespace ztd {
using namespace std;
template <typename T>
inline T read(T& t) {
  t = 0;
  short f = 1;
  char ch = getchar();
  double d = 0.1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t *= f;
  return t;
}
}  // namespace ztd
using namespace ztd;
int n, a, mx;
long long ans;
signed main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a);
    if (a > mx)
      a = mx;
    else
      ans += (mx - a);
  }
  cout << ans << endl;
  return 0;
}
