var
yes:boolean;
i,l1,l2,now,j,k:longint;
ch:char;
s1,s2:array[0..1000000]of ansistring;
a,b:array[0..1000000]of longint;
begin
assign(input,'kriptogram.in'); reset(input);
assign(output,'kriptogram.out'); rewrite(output);
l1:=0;
repeat
inc(l1);
read(ch);
if ch='$' then break;
repeat
s1[l1]:=s1[l1]+ch;
read(ch);
until ch=' ';
until false;
readln;
l2:=0;
repeat
inc(l2);
read(ch);
if ch='$' then break;
repeat
s2[l2]:=s2[l2]+ch;
read(ch);
until ch=' ';
until false;
dec(l1);
dec(l2);
now:=0;
for i:=1 to l2 do
begin
for j:=1 to i-1 do
if s2[i]=s2[j] then
begin
b[i]:=b[j];
break;
end;
if b[i]=0 then
begin
inc(now);
b[i]:=now;
end;
end;
for k:=1 to l1-l2+1 do
begin
now:=0;
yes:=true;
for i:=k to k+l2-1 do
begin
a[i-k+1]:=0;
for j:=k to i-1 do
if s1[i]=s1[j] then
begin
a[i-k+1]:=a[j-k+1];
break;
end;
if a[i-k+1]=0 then
begin
inc(now);
a[i-k+1]:=now;
end;
if a[i-k+1]<>b[i-k+1] then
begin
yes:=false;
break;
end;
end;
if yes then
begin
writeln(k);
break;
end;
end;
close(input);
close(output);
end.