var
a, b, c: longint;
d: byte;
begin
readln(a,b);
while a > 0 do begin
d := a mod 10;
a := a div 10;
c := b;
while c > 0 do begin
if c mod 10 = d then begin
write(d,' ');
break;
end;
c := c div 10;
writeln;
end.
/0
1/3*6?wwwhdjdjdkn-===
var
a, b, c: longint;
d: byte;
begin
readln(a,b);
while a > 0 do begin
d := a mod 10;
a := a div 10;
c := b;
while c > 0 do begin
if c mod 10 = d then begin
write(d,' ');
break;
end;
c := c div 10;
end;
end;
writeln;
end.
/0
1/3*6?wwwhdjdjdkn-===