{
TASK:digits
LANG:PASCAL
}
var
	b,c,d			: longint;
	i,j,p			: integer;
    br              : longint;

    n,k,r,m			: integer;
    str3			: string;
    str2			: string;
	car				: integer;
begin
	readln(r,m,k);
    if (k=10) and (r<2000000) then
    	begin
        	readln(b);
            str(m,str2);
            br:=1;
            b:=b-1;
        	for c:= 1 to b do
            	begin
                	str(c,str3);
                    while pos(str2,str3)>0 do
                    	begin
                        	str3[pos(str2,str3)]:='x';
                            inc(br);
                        end;
                end;
            writeln(br);
        end
    else
    	begin
        	readln(str3);
            writeln('3CMATS');
        end;
end.