#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9 + 5;
char s[1005][15];
int v[50], val[50];
int n, ans = Inf;
bool use[50], first[50];
void bkt(int pos, int sum) {
  if (pos > 10) {
    ans = min(ans, sum);
    return;
  }
  for (int i = 0; i < 10; ++i) {
    if (use[i] == false && (first[pos] == false || i != 0)) {
      v[pos] = i;
      use[i] = true;
      bkt(pos + 1, sum + val[pos] * i);
      use[i] = false;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    int lg = strlen(s[i]);
    first[s[i][0] - 'a' + 1] = true;
    int pt = 1;
    for (int j = lg - 1; j >= 0; --j) {
      val[s[i][j] - 'a' + 1] += pt;
      pt *= 10;
    }
  }
  bkt(1, 0);
  cout << ans << '\n';
  return 0;
}
