#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int v, w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int N; cin >> N; vector V(N); for (int i = 0; i < N; i++) cin >> V[i]; string s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int x = 0; vector > v(N); for (int i = 0; i < N; i++) for (int j = 0; j < V[i].length(); j++) { char c = V[i][j]; int k; for (k = 0; k < 36; k++) if (s[k] == c) break; v[i].push_back(k); x = max(x, k + 1); } ll mini = LLONG_MAX; for (int i = 0; i < N; i++) { ll y = 0; for (int j = 0; j < v[i].size(); j++) y = y * x + v[i][j]; mini = min(mini, y); } cout << mini << endl; }