def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  i = A[0]
  T = 0
  
  for n in A:
    if n > i:
      T += n -i
    if n < i:
      T = i
  
  print(T)

if __name__ == "__main__":
    main()