#include <bits/stdc++.h>
using namespace std;
int main() {
  int max;
  cin >> max;
  int prev = 0;
  int result = 0;
  for (int i = 0; max > i; i++) {
    int num;
    cin >> num;
    if (i == 0) {
      prev = num;
      continue;
    }
    if (prev > num) {
      cout << prev << "," << num << endl;
      result += prev - num;
    }
    prev = prev > num ? prev : num;
  }
  cout << result << endl;
  return 0;
}
