import std.array, std.stdio, std.string, std.algorithm, std.conv; void main() { int N = readln.strip.to!int; ulong min = ulong.max; foreach (i; 0..N) { string s = readln.strip; ulong ret = minNum(s); if (ret < min) min = ret; } writeln(min); } string base36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ulong minNum(string n) { char max = n.minPos!"cast(int)a > cast(int)b".front.to!char; int base; if ('0' <= max && max <= '9') { base = (max - '0').to!int + 1; } else { base = 10 - 'A' + max + 1; } ulong ret = 0; foreach (i, c; n.dup.reverse) { ret += base36.indexOf(c) * base ^^ i; } return ret; }