#include <bits/stdc++.h>
using namespace std;
bool checkbit(int x, int y) { return (x & (1 << y)); }
int setbit(int x, int y) { return (x ^ (1 << y)); }
const int dirs[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int mod = (1e9 + 7);
const long long INF = LLONG_MAX;
const int maxn = 0;
int n;
vector<int> dig;
long long val[10 + 1];
bool cantb[10 + 1];
long long minsum = INF;
bool free_fr[10 + 1];
void fun(int i, long long presum) {
  if (i == 10) {
    minsum = min(minsum, presum);
    return;
  }
  for (int j = (0); j < (9 + 1); j++) {
    if (free_fr[j] && (j != 0 || (j == 0 && !cantb[i]))) {
      free_fr[j] = 0;
      fun(i + 1, presum + (val[i] * j));
      free_fr[j] = 1;
    }
  }
}
int main() {
  for (int i = (0); i < (10); i++) free_fr[i] = 1;
  int faktof10 = 1;
  for (int i = (1); i < (10 + 1); i++) faktof10 *= i;
  for (int i = (0); i < (9 + 1); i++) dig.push_back(i);
  scanf("%d", &n);
  for (int j = (0); j < (n); j++) {
    char st[12345];
    scanf(" %s", st);
    long long exp = 1;
    cantb[st[0] - 'a'] = 1;
    for (int i = strlen(st) - 1; i >= 0; i--) {
      val[st[i] - 'a'] += exp;
      exp *= 10;
    }
  }
  fun(0, 0);
  cout << minsum << "\n";
  return 0;
}
