#include <bits/stdc++.h>
using namespace std;
const int64_t posinf = 9223372036854775807LL;
const int64_t neginf = 9223372036854775808LL;
const uint64_t ullinf = 18446744073709551615ULL;
const uint64_t bigprime = 2305843009213693951ULL;
const uint64_t smallprime = 2147483647ULL;
const int prime = 3571;
const int ssspr = 199;
const int64_t modbase = 1000000007LL;
const int64_t inv2mod = 500000004LL;
const int sneginf = -2147483647;
bool lid[10];
int sum[10];
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    lid[s.back() - 'a'] = true;
    int pw = 1;
    for (char c : s) {
      sum[c - 'a'] += pw;
      pw *= 10;
    }
  }
  int ids[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int mans = 1500000000;
  do {
    if (lid[ids[0]]) continue;
    int ans = 0;
    for (int i = 1; i < 10; i++) ans += sum[ids[i]] * i;
    mans = min(mans, ans);
  } while (next_permutation(ids, ids + 10));
  cout << mans;
  ;
  return 0;
}
