program Numbering;
var
s1,s2:string;
N,i,a,b,t,l,k,j:integer;
arr:array[1..10] of integer;        Int:set of 0..9;

function f(x:char):integer;
begin
case x of
'0':f:=0;     '2':f:=2;
'1':f:=1;     '3':f:=3;
'4':f:=4;  '5':f:=5; '6':f:=6; '7':f:=7; '8':f:=8; '9':f:=9;
end;
end;

begin
 readln(s1);
readln(s2);
a:=length(s1);
b:=length(s2);
t:=1;
while t<=a do begin
exclude(Int,f(s1[t]));
t:=t+2;
end;
t:=t-2;
t:=t div 2 +1;
l:=10-t;
N:=0; k:=1;
for i:=0 to 9 do if i in Int then begin
 arr[k]:=i ; k:=k+1;
 end;
 k:=k-1;
for i:=1 to b do
for j:=1 to k do
if f(s2[i])=arr[j] then N:=N+j*round(exp(ln(l)*(b-i)));
write(N);       end.
