import collections s1 = str(input()) s2 = str(input()) if collections.Counter(s1)!=collections.Counter(s2):     print(-1) else:     pref = ""     for s in s2:         if s in s1:             pref += s             s1 = s1[s1.index(s)+1:]         else:             break     print(len(s2)-len(pref))