#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int vis[10];
  memset(vis, 0, sizeof(vis));
  int val[10];
  memset(val, 0, sizeof(val));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = s.size() - 1; j >= 0; j--) {
      val[s[j] - 'a'] += (int)pow(10, s.size() - 1 - j);
    }
    vis[s[0] - 'a'] = true;
  }
  int ans = 1e9;
  vector<int> v;
  for (int i = 0; i <= 9; i++) {
    v.push_back(i);
  }
  do {
    if (vis[v[0]]) {
      continue;
    }
    int sum = 0;
    for (int i = 0; i <= 9; i++) {
      sum += val[v[i]] * i;
    }
    ans = min(ans, sum);
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << "\n";
  return 0;
}
