import 'dart:io';
import 'dart:math';

void main() {
  int n = int.parse(stdin.readLineSync());
  List aList =
      stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int sum = 0;
  int s = 0;

  for (int i = 1; i < n; i++) {
    int sLength = aList[s].toString().length;
    int iLength = aList[i].toString().length;
    int diffLength = sLength - iLength;
    // print("diffLength$diffLength");
    if (diffLength < 0) {
      s = i;
    } else if (diffLength == 0) {
      int diff = (aList[s] - (aList[i]));
      // print(diff);
      if (diff > 0) {
        sum = sum + diff;
      } else if (diff < 0) {
        s = i;
      }
    } else {
      // int pows = pow(10, diffLength);
      // int diff0 = (aList[s] / pows).floor();
      String diff0 = aList[s].toString().substring(0, diffLength - 1);
      // print("diff0$diff0");
      // print(int.parse(aList[s].toString().substring(diffLength - 1, sLength)));
      // int diff1 = (aList[s] - diff0 * pows) - (aList[i]);
      int diff1 =
          int.parse(aList[s].toString().substring(diffLength - 1, sLength)) -
              aList[i];

      String diffSt = diff0 + diff1.toString();
      // print("rr");
      int diff = int.parse(diffSt);
      // int diff = (aList[s] - (aList[i]));
      if (diff > 0) {
        sum = sum + diff;
      } else if (diff < 0) {
        s = i;
      }
    }
  }
  print(sum);
}
