#include <bits/stdc++.h>
using namespace std;
const long long N = 10;
vector<long long> ways = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
long long tot[N], p10[N], notzero[N];
void calc() {
  p10[0] = 1;
  for (long long i = 1; i < 10; i++) p10[i] = 10 * p10[i - 1];
}
long long get() {
  long long ret = 0;
  for (long long i = 0; i < 10; i++) {
    ret += tot[ways[i]] * i;
  }
  return ret;
}
signed main() {
  std ::ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  calc();
  long long n;
  cin >> n;
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    string second;
    cin >> second;
    notzero[second[0] - 'a'] = true;
    long long len = second.length();
    for (long long j = 0; j < len; j++) {
      tot[second[j] - 'a'] += p10[len - j - 1];
    }
  }
  long long best = 2e18;
  do {
    if (notzero[ways[0]]) continue;
    best = min(best, get());
  } while (next_permutation((ways).begin(), (ways).end()));
  cout << best;
}
