s=eval(input())

t=eval(input())

if len(set(t)-set(s))>0:

  print((-1))

  exit(0)



ss=s*2

ind=-1

turn=0

for c in t:

  nex=ss[ind+1:].find(c)

  ind=(ind+1)+nex

  if ind>=len(s):

    ind-=len(s)

    turn+=1



print((turn*len(s)+ind+1))
s=eval(input())

t=eval(input())



if len(set(t)-set(s))>0:

  print((-1))

else:

  s2=s*2

  s2pos={}

  for i in range(len(s2)):

    if s2[i] in s2pos:

      s2pos[s2[i]].append(i)

    else:

      s2pos[s2[i]]=[i]



  cur=-1

  import bisect

  rev=0

  for c in t:

    cur+=1

    pos=s2pos[c]

    p=bisect.bisect_left(pos,cur)

    cur=pos[p]

    if cur>=len(s):

      cur-=len(s)

      rev+=1

  else:

    print((rev*len(s)+cur+1))

s = eval(input())
t = eval(input())
if len(set(t) - set(s)) > 0:
    print((-1))
    exit(0)
ss = s * 2
ind = -1
turn = 0
for c in t:
    nex = ss[ind + 1 :].find(c)
    ind = (ind + 1) + nex
    if ind >= len(s):
        ind -= len(s)
        turn += 1
print((turn * len(s) + ind + 1))

s = eval(input())
t = eval(input())
if len(set(t) - set(s)) > 0:
    print((-1))
else:
    s2 = s * 2
    s2pos = {}
    for i in range(len(s2)):
        if s2[i] in s2pos:
            s2pos[s2[i]].append(i)
        else:
            s2pos[s2[i]] = [i]
    cur = -1
    import bisect

    rev = 0
    for c in t:
        cur += 1
        pos = s2pos[c]
        p = bisect.bisect_left(pos, cur)
        cur = pos[p]
        if cur >= len(s):
            cur -= len(s)
            rev += 1
    else:
        print((rev * len(s) + cur + 1))

-    exit(0) -ss = s * 2 -ind = -1 -turn = 0 -for c in t: -    nex = ss[ind + 1 :].find(c) -    ind = (ind + 1) + nex -    if ind >= len(s): -        ind -= len(s) -        turn += 1 -print((turn * len(s) + ind + 1)) +else: +    s2 = s * 2 +    s2pos = {} +    for i in range(len(s2)): +        if s2[i] in s2pos: +            s2pos[s2[i]].append(i) +        else: +            s2pos[s2[i]] = [i] +    cur = -1 +    import bisect + +    rev = 0 +    for c in t: +        cur += 1 +        pos = s2pos[c] +        p = bisect.bisect_left(pos, cur) +        cur = pos[p] +        if cur >= len(s): +            cur -= len(s) +            rev += 1 +    else: +        print((rev * len(s) + cur + 1))