#include int f(char c) { if ('0' <= c && c <= '9') return c - '0'; else return c - 'A' + 10; } int main() { int n; scanf("%d", &n); int i, j; char v[16]; long long int ans = 1000000000000000000; long long int r, p; for (j = 0; j < n; j++) { scanf("%s", v); p = 0; for (i = 0; v[i] != '\0'; i++) if (p < f(v[i])) p = f(v[i]); p++; r = 0; for (i = 0; v[i] != '\0'; i++) r = p * r + f(v[i]); if (ans > r) ans = r; } printf("%lld\n", ans); return 0; }