program Hello;
var number,val:integer;
begin
readln(number);
readln(val);
while(number<>0)
do
if number mod 10 = val then
val:= val + 1;
end;
number:= number div 10;
writeln(val);
end.
program Hello;
var number,val:integer;
begin
readln(number);
readln(val);
while(number<>0)
do
begin
if number mod 10 = val then
begin
val:= val + 1;
end;
number:= number div 10;
end;
writeln(val);
end.