Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​m pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.


-----Input-----

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.

The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.


-----Output-----

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.


-----Examples-----
Input
aaabbac
aabbccac

Output
6

Input
a
z

Output
-1


-----Note-----

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z.

Difficulty: EASY

Solutions:
str1 = input()
str2 = input()
cnt1 = dict()
cnt2 = dict()
for x in str1:
	if x not in cnt1.keys():
		cnt1[x] = 0
	cnt1[x] += 1
for x in str2:
	if x not in cnt2.keys():
		cnt2[x] = 0
	cnt2[x] += 1
s = 0
for x in cnt2.keys():
	if x not in cnt1.keys():
		print(-1)
		exit(0)
	s += min(cnt1[x], cnt2[x])
print(s)


import sys
have = input()
need = input()
pl = 0
alph = 'abcdefghijklmnopqrstuvwxyz'
for l in alph:
	if l in need:
		if l not in have:
			print(-1)
			sys.exit()
		pl += min(have.count(l), need.count(l))
print(pl)


n = input()
m = input()
total_c = 0
for i in m:
	n_count = n.count(i)
	if n_count == 0:
		total_c = 0
		break
	total_c += min(n_count, m.count(i))
	m = m.replace(i, '')
if total_c == 0:
	total_c -= 1
print(total_c)


import sys
color = list(input())
garland = list(input())
for i in garland:
	if i not in color:
		print(-1)
		sys.exit()
cou = 0
for i in set(color):
	cou += min(color.count(i), garland.count(i))
print(cou)


a = input()
b = input()
x = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
y = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
for i in a:
	x[i] += 1
for i in b:
	y[i] += 1
area = 0
for c in 'abcdefghijklmnopqrstuvwxyz':
	if x[c] == 0 and y[c] != 0:
		print('-1')
		quit()
	else:
		area += min(x[c], y[c])
print(area)


a = input()
b = input()
x = [0] * 26
y = [0] * 26
for c in a:
	x[ord(c) - ord('a')] += 1
for c in b:
	y[ord(c) - ord('a')] += 1
result = 0
for i in range(26):
	if x[i] == 0 and y[i] > 0:
		result = -1
		break
	result += min(x[i], y[i])
print(result)


from collections import Counter

def solve():
	n = input()
	m = input()
	for i in m:
		if i not in n:
			ans = -1
			return ans
	cn = Counter(n)
	cm = Counter(m)
	ans = 0
	for (k, v) in cm.items():
		v2 = cn[k]
		if v > v2:
			ans += v2
		else:
			ans += v
	return ans
ans = solve()
print(ans)


paper = input()
P = [0 for i in range(26)]
for c in paper:
	P[ord(c) - ord('a')] += 1
design = input()
D = [0 for i in range(26)]
for c in design:
	D[ord(c) - ord('a')] += 1
co = True
for i in range(26):
	if P[i] == 0 and D[i] > 0:
		co = False
if co:
	Area = 0
	for i in range(26):
		if P[i] >= D[i]:
			Area += D[i]
		else:
			Area += P[i]
	print(Area)
else:
	print('-1')


from collections import Counter
n = dict(Counter(input()))
m = dict(Counter(input()))
ans = 0
for color in m:
	if color in n:
		ans += min(n[color], m[color])
	else:
		print(-1)
		break
else:
	print(ans)


a = input()
b = input()
res = 0
for i in range(ord('a'), ord('z') + 1):
	c = chr(i)
	if a.count(c) == 0 and b.count(c) == 0:
		continue
	if a.count(c) == 0 and b.count(c) > 0:
		print(-1)
		exit()
	res = res + min(a.count(c), b.count(c))
print(res)


from collections import Counter
available_colors = Counter(input())
target_colors = Counter(input())
ans = 0
for color in target_colors:
	m = min(available_colors[color], target_colors[color])
	if m == 0:
		ans = -1
		break
	else:
		ans += m
print(ans)


(n, m) = (input(), input())
ms = set(m)
ans = 0
for k in ms:
	if not n.__contains__(k):
		ans = -1
		break
	if n.count(k) >= m.count(k):
		ans += m.count(k)
	else:
		ans += n.count(k)
print(ans)


s = input()
s1 = input()
d = {}
d1 = {}
for x in s:
	d[x] = d.get(x, 0) + 1
k = 0
for x in s1:
	d1[x] = d1.get(x, 0) + 1
for x in d1:
	e = min(d1[x], d.get(x, 0))
	if e == 0:
		print(-1)
		exit()
	k += e
print(k)


from collections import Counter
n = Counter(input())
m = Counter(input())
ans = 0
for i in range(0, 26):
	if m[chr(ord('a') + i)] > 0 and n[chr(ord('a') + i)] == 0:
		print(-1)
		exit()
	ans += min(m[chr(ord('a') + i)], n[chr(ord('a') + i)])
print(ans)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(s1, s2) = (is1(), is1())
d1 = {}
for i in s1:
	d1.setdefault(i, [0])[0] += 1
d2 = {}
for i in s2:
	d2.setdefault(i, [0])[0] += 1
ans = 0
for i in d2:
	cur = d1.get(i, [0])[0]
	if cur >= d2[i][0]:
		ans += d2[i][0]
	elif cur > 0:
		ans += cur
	else:
		ans = -1
		break
print(ans)


n = input()
m = input()
c = set(m)
ans = 0
for colour in c:
	nc = n.count(colour)
	mc = m.count(colour)
	if nc == 0:
		ans = -1
		break
	else:
		ans += min(nc, mc)
print(ans)


def main():
	(a, b, res) = ([0] * 26, [0] * 26, 0)
	for l in (a, b):
		for c in input():
			l[ord(c) - 97] += 1
	for (x, y) in zip(a, b):
		if y:
			if x:
				res += x if x < y else y
			else:
				res = -1
				break
	print(res)
main()


def main():
	folhas = input()
	guirlanda = input()
	dic_f = area(folhas)
	dic_g = area(guirlanda)
	tot_area_p = 0
	for folha in dic_g.keys():
		if folha not in dic_f.keys():
			print(-1)
			return
		elif dic_g[folha] < dic_f[folha]:
			tot_area_p += dic_g[folha]
		else:
			tot_area_p += dic_f[folha]
	print(tot_area_p)

def area(folhas):
	dic = {}
	for folha in folhas:
		if folha not in dic.keys():
			dic[folha] = folhas.count(folha)
	return dic
main()


def main():
	from sys import stdin, stdout
	import collections
	inp = stdin.readline().strip()
	out = stdin.readline().strip()
	counter = 0
	flag = True
	inp = collections.Counter(inp)
	out = collections.Counter(out)
	for key in out:
		if inp[key]:
			counter += min(inp[key], out[key])
		else:
			flag = False
			break
	if flag:
		stdout.write(str(counter))
	else:
		stdout.write('-1')
main()


(n, p) = (input(), input())
print(-1 if len(set(p) - set(n)) != 0 else sum([min(n.count(i), p.count(i)) for i in set(n)]))


(n, m) = (input(), input())
t = 0
for l in set(m):
	c = min(n.count(l), m.count(l))
	if c == 0:
		print(-1)
		break
	t += c
else:
	print(t)


from collections import defaultdict
have = input()
need = input()
havec = defaultdict(int)
needc = defaultdict(int)
for c in have:
	havec[c] += 1
for c in need:
	needc[c] += 1
ans = 0
for c in dict(needc).keys():
	if c not in havec:
		print('-1')
		exit()
	ans += min(havec[c], needc[c])
print(ans)


a = ''.join(sorted(input()))
b = ''.join(sorted(input()))
(aDic, bDic) = ({}, {})
for i in a:
	aDic[ord(i) - ord('a')] = a.count(i)
for i in b:
	bDic[ord(i) - ord('a')] = b.count(i)
cont = 0
for (z, v) in bDic.items():
	try:
		if aDic[z]:
			if bDic[z]:
				cont += min(aDic[z], bDic[z])
	except KeyError:
		cont = 0
		break
print(cont if cont > 0 else '-1')


z = [0] * 27
z1 = [0] * 27
for i in input():
	z[ord(i) - 97] += 1
for i in input():
	z1[ord(i) - 97] += 1
s = 0
for i in range(27):
	if z[i] >= z1[i]:
		s += z1[i]
	elif z1[i] != 0 and z[i] != 0:
		s += z[i]
	if z1[i] and (not z[i]):
		exit(print(-1))
print(s)


s1 = input()
s2 = input()
ct1 = [0] * 26
ct2 = [0] * 26
for ch in s1:
	i = ord(ch) - ord('a')
	ct1[i] += 1
for ch in s2:
	i = ord(ch) - ord('a')
	ct2[i] += 1
res = 0
for i in range(26):
	if ct2[i] > 0 and ct1[i] == 0:
		res = -1
		break
	if ct2[i] == ct1[i]:
		res += ct2[i]
	elif ct2[i] > ct1[i]:
		res += ct1[i]
	else:
		res += ct2[i]
print(res)


s = input()
t = input()
r = list(set(t))
for i in range(len(t)):
	if t[i] not in s:
		print(-1)
		exit()
area = 0
for obj in r:
	area += min(s.count(obj), t.count(obj))
print(area)


s = list(input())
c = list(input())
q = []
for i in c:
	if i in s:
		q.append(i)
		del s[s.index(i)]
	elif i in q:
		pass
	else:
		print(-1)
		exit()
print(len(q))


import sys
import math

def fn(n, m):
	cnt = [0] * 123
	cnt1 = [0] * 123
	n = list(n)
	m = list(m)
	m1 = list(set(m))
	for i in range(len(n)):
		cnt[ord(n[i])] = cnt[ord(n[i])] + 1
	for i in range(len(m)):
		cnt1[ord(m[i])] = cnt1[ord(m[i])] + 1
	for i in range(len(m)):
		if cnt[ord(m[i])] == 0:
			return -1
	a = 0
	for i in range(len(m1)):
		if cnt1[ord(m1[i])] <= cnt[ord(m1[i])]:
			a = a + cnt1[ord(m1[i])]
		elif cnt1[ord(m1[i])] > cnt[ord(m1[i])]:
			a = a + cnt[ord(m1[i])]
	return a
input = sys.stdin.read()
data = list(map(str, input.split()))
n = data[0]
m = data[1]
print(fn(n, m))


colors = list(input())
colors.sort()
wants = list(input())
wants.sort()
res = 0
hecan = 1
for c in wants:
	if c not in colors:
		hecan = 0
ca = sorted(set(colors))
wa = sorted(set(colors))
for c in ca:
	if colors.count(c) >= wants.count(c):
		res += wants.count(c)
	else:
		res += colors.count(c)
if hecan == 0:
	print(-1)
else:
	print(res)


import sys
s = input()
s1 = input()
ans = 0
x = [0] * 27
y = [0] * 27
for i in range(len(s)):
	x[ord(s[i]) - 97] += 1
for i in range(len(s1)):
	y[ord(s1[i]) - 97] += 1
for i in range(27):
	if x[i] == 0 and y[i] != 0:
		print(-1)
		sys.exit()
	ans += min(x[i], y[i])
print(ans)


a1 = input()
a2 = input()
slon = 0
for i in range(ord('a'), ord('z') + 1):
	x = chr(i)
	count1 = a1.count(x)
	count2 = a2.count(x)
	if count1 == 0 and count2 != 0:
		print(-1)
		exit(0)
	elif count1 >= count2:
		slon += count2
	else:
		slon += count1
print(slon)


n = input()
n = list(n)
m = input()
m = list(m)
counted = []
count = 0
for i in m:
	if i in n:
		if i not in counted:
			if m.count(i) <= n.count(i):
				count += m.count(i)
				counted.append(i)
			else:
				count += n.count(i)
				counted.append(i)
	else:
		count = -1
		break
if count:
	print(count)
else:
	print(-1)


a = input()
b = input()
dict1 = {}
dict2 = {}
for i in range(0, len(a)):
	if a[i] in dict1:
		dict1[a[i]] += 1
	else:
		dict1[a[i]] = 1
act = set()
for j in range(0, len(b)):
	act.add(b[j])
	if b[j] in dict2:
		dict2[b[j]] += 1
	else:
		dict2[b[j]] = 1
		if b[j] not in dict1:
			dict1[b[j]] = 0
z = list(act)
ctr = 0
char = 0
for i in range(0, len(z)):
	ctr += min(dict1[z[i]], dict2[z[i]])
	if min(dict1[z[i]], dict2[z[i]]) != 0:
		char += 1
if ctr > 0 and char == len(z):
	print(ctr)
else:
	print(-1)


sheet = input()
garland = input()
sheetnum = dict()
garlandnum = dict()
for color in sheet:
	if not color in sheetnum:
		sheetnum[color] = 1
	else:
		sheetnum[color] = sheetnum[color] + 1
for color in garland:
	if not color in garlandnum:
		garlandnum[color] = 1
	else:
		garlandnum[color] = garlandnum[color] + 1
ans = 0
for color in garlandnum.keys():
	if not color in sheetnum:
		ans = -1
		break
	if garlandnum[color] >= sheetnum[color]:
		ans = ans + sheetnum[color]
	else:
		ans = ans + garlandnum[color]
print(ans)


(s1, s2) = (input(), input())
(lst1, lst2, ans) = ([], [], 0)
s = 'abcdefghijklmnopqrstuvwxyz'
for ch in s:
	lst1.append(s1.count(ch))
	lst2.append(s2.count(ch))
for i in range(26):
	if lst2[i] > 0 and lst1[i] == 0:
		print('-1')
		exit()
	if lst2[i] > 0 and lst1[i] > 0:
		ans += min(lst1[i], lst2[i])
print(ans)


si = lambda : input()
from collections import Counter
r = Counter(si())
g = Counter(si())
z = a = 0
if len(g.keys() - r.keys()) > 0:
	z = -1
else:
	for i in g.keys():
		if g[i] < r[i]:
			a += g[i]
		else:
			a += r[i]
print(-1 if z == -1 else a)


import collections

def m():
	n = input()
	m = input()
	nhash = collections.defaultdict(int)
	mhash = collections.defaultdict(int)
	for i in n:
		nhash[i] += 1
	for i in m:
		mhash[i] += 1
	sum = 0
	for (i, k) in mhash.items():
		if nhash[i] == 0:
			return 0
		sum += min(k, nhash[i])
	return sum
res = m()
if res == 0:
	print(-1)
else:
	print(res)


def solve():
	s = input()
	t = input()
	s_map = {}
	t_map = {}
	for i in s:
		if i not in s_map:
			s_map[i] = 0
		s_map[i] += 1
	for i in t:
		if i not in t_map:
			t_map[i] = 0
		t_map[i] += 1
	ans = 0
	for i in t:
		if i not in s:
			print(-1)
			return 0
	else:
		for i in s_map.keys():
			if i in t_map:
				if s_map[i] >= t_map[i]:
					ans += t_map[i]
				else:
					ans += s_map[i]
	print(ans)
solve()


from sys import stdin, stdout
from collections import Counter
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, input().split()))
for i in range(1):
	d = Counter(input())
	d1 = Counter(input())
	ans = 0
	for (k, v) in d1.items():
		if k not in d:
			ans = 0
			break
		ans += min(v, d.get(k, 0))
	print(ans if ans else -1)
3


from collections import Counter as C
s = str(input())
t = str(input())
se = list(set(t))
cs = C(s)
ct = C(t)
ar = 0
for i in se:
	if cs[i] == 0:
		print(-1)
		exit()
	ar += min(cs[i], ct[i])
print(ar)


import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
n = data()
m = data()
(s1, s2) = (c(n), c(m))
answer = 0
result = True
for i in s2.keys():
	if i not in s1.keys():
		result = False
		break
	answer += min(s1[i], s2[i])
if answer == 0 or not result:
	out('-1')
	exit()
out(str(answer))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(a, b):
	tot = 0
	ff = True
	for i in set(b):
		if i != '\n':
			if i in a:
				if b.count(i) > a.count(i):
					tot += a.count(i)
				else:
					tot += b.count(i)
			else:
				ff = False
				break
	if ff:
		print(tot)
	else:
		print(-1)
a = str(input())
b = str(input())
solve(a, b)


s1 = input()
s2 = input()
from collections import Counter
c1 = Counter(s1)
c2 = Counter(s2)
ans = True
c = 0
for i in c2:
	if c1[i] == 0:
		ans = False
		break
	if c2[i] <= c1[i]:
		c += c2[i]
	else:
		c += c1[i]
if ans == True:
	print(c)
else:
	print(-1)


from collections import defaultdict
(s, a, b) = (0, defaultdict(int), defaultdict(int))
for i in input():
	a[i] += 1
for i in input():
	b[i] += 1
for i in b:
	if i in a:
		s += min(a[i], b[i])
	else:
		s = -1
		break
print(s)


s = list(input())
m = list(input())
c1 = [0] * 26
c2 = [0] * 26
for c in s:
	c1[ord(c) - ord('a')] += 1
for c in m:
	c2[ord(c) - ord('a')] += 1
sm = 0
for i in range(26):
	if c2[i] > 0 and c1[i] == 0:
		sm = -1
		break
	else:
		sm += min(c1[i], c2[i])
print(sm)


from collections import deque as de
import math
import sys
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic
n = si()
m = si()
ndic = get_frequency(n)
mdic = get_frequency(m)
ans = 0
ch = 1
for key in mdic:
	if key not in ndic:
		ch = 0
		print(-1)
		break
	elif mdic[key] >= ndic[key]:
		ans += ndic[key]
	else:
		ans += mdic[key]
if ch:
	print(ans)


from collections import *
s = input()
r = input()
x = Counter(s)
y = Counter(r)
c = 0
for i in y:
	if x[i] == 0:
		print(-1)
		break
	elif x[i] >= y[i]:
		c += y[i]
	else:
		c += x[i]
else:
	print(c)


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
arr1 = input()
arr2 = input()
ans = 0
dicts1 = {}
dicts2 = {}
for k in arr1:
	if k not in dicts1:
		dicts1[k] = 1
	else:
		dicts1[k] += 1
for k in arr2:
	if k not in dicts2:
		dicts2[k] = 1
	else:
		dicts2[k] += 1
ans = 0
flag = 0
for (key, value) in dicts2.items():
	if key not in dicts1:
		flag = 1
		break
	else:
		val1 = dicts1[key]
		ans += min(val1, value)
if flag == 1:
	print(-1)
elif ans != 0:
	print(ans)
else:
	print(-1)


def main():
	import sys
	material = input()
	scheme = input()
	flag = True
	for i in range(len(scheme)):
		if flag:
			if not scheme[i] in material:
				print(-1)
				flag = False
	if flag:
		counter = 0
		SIZE = len(scheme) - 1
		saver = []
		result = 0
		while counter <= SIZE:
			saver += [scheme[counter]]
			if scheme.count(scheme[counter]) <= material.count(scheme[counter]):
				result += scheme.count(scheme[counter])
			else:
				result += material.count(scheme[counter])
			while scheme[counter] in saver:
				if counter < SIZE:
					counter += 1
				else:
					print(result)
					return
		print(result)
main()


def main():
	from collections import Counter
	n = Counter(list(input()))
	m = Counter(list(input()))
	ret = 0
	s = set()
	for c in m:
		if c in n and n[c] >= m[c]:
			s.add(c)
			ret += m[c]
			n[c] -= m[c]
			m[c] = 0
		elif c in n and n[c] < m[c]:
			s.add(c)
			ret += n[c]
			m[c] -= n[c]
			n[c] -= n[c]
		elif c not in n:
			return -1
	for c in m:
		if c in s:
			continue
		if c in n and m[c] > 0 and (n[c] >= 0):
			ret += 1
			m[c] = 0
	return ret if ret > 0 else -1
print(main())


n = input()
l = list(n)
m = input()
k = list(m)
count = 0
s = 0
flag = 0
w = set(k)
for i in k:
	if i not in l:
		flag = -1
		print(flag)
		break
if flag != -1:
	for i in w:
		s = s + min(k.count(i), l.count(i))
	print(s)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
from collections import Counter
A = input()
c1 = Counter(A)
B = input()
c2 = Counter(B)
ans = 0
for c in c2:
	if c1[c] == 0:
		print(-1)
		break
	if c1[c] >= c2[c]:
		ans += c2[c]
	else:
		ans += c1[c]
else:
	print(ans)


from collections import Counter
c1 = Counter(input())
c2 = Counter(input())
count = 0
for ch in c2:
	if ch not in c1:
		print(-1)
		exit()
	else:
		count += min(c1[ch], c2[ch])
print(count)


s = input()
w = input()
s = sorted(s)
w = sorted(w)
set_s = set(s)
set_w = set(w)
for i in set_w:
	if i not in set_s:
		print(-1)
		exit()
ans = 0
for i in set_w:
	a = w.count(i)
	b = s.count(i)
	if b >= a:
		ans += a
	else:
		ans += b
print(ans)


ans = 0
one = [0] * 26
two = [0] * 26
for i in input():
	one[ord(i) - 97] += 1
for i in input():
	two[ord(i) - 97] += 1
for i in range(26):
	if one[i] == 0 and two[i] > 0:
		exit(print(-1))
	ans += min(two[i], one[i])
print(ans)


from collections import *
(n, m) = [defaultdict(int, Counter(input())) for i in range(2)]
ans = 0
for (i, j) in m.items():
	if n[i] == 0:
		exit(print(-1))
	else:
		ans += min(n[i], j)
print(ans)


import sys
import math
n = sys.stdin.readline()
m = sys.stdin.readline()
kn = [0] * 26
km = [0] * 26
for i in n:
	if i != '\n':
		kn[ord(i) - ord('a')] += 1
for i in m:
	if i != '\n':
		km[ord(i) - ord('a')] += 1
res = 0
for i in range(26):
	v = min(kn[i], km[i])
	if kn[i] == 0 and km[i] > 0:
		print(-1)
		exit()
	res += v
print(res)


s = input()
ss = input()
t = set(ss)
t = list(t)
for i in t:
	if i not in s:
		print(-1)
		break
else:
	sum1 = 0
	for i in t:
		sum1 += min(s.count(i), ss.count(i))
	print(sum1)


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from math import pi
from collections import Counter as C
a = list(input())
b = list(input())
c = C(a)
d = C(b)
s = set(b)
b = list(s)
ar = 0
for i in b:
	if c[i] == 0:
		print(-1)
		exit()
	elif c[i] >= d[i]:
		ar += d[i]
	else:
		ar += c[i]
print(ar)


n = sorted(list(input()))
k = sorted(list(input()))
d = {}
ans = 0
flag = 1
for i in k:
	if i in n:
		if i not in d:
			c = n.count(i)
			b = k.count(i)
			if c >= b:
				ans += b
			else:
				ans += c
			d[i] = 1
	else:
		flag = 0
		break
if flag:
	print(ans)
else:
	print(-1)


n = input()
m = input()
given = {}
req = {}
for i in range(97, 123):
	given[chr(i)] = 0
	req[chr(i)] = 0
for i in range(len(n)):
	given[n[i]] += 1
for i in range(len(m)):
	req[m[i]] += 1
flag = 0
for i in m:
	if i not in n:
		flag = 1
		break
if flag:
	print(-1)
else:
	area = 0
	for i in range(97, 123):
		if req[chr(i)] != 0 and given[chr(i)] != 0:
			if given[chr(i)] >= req[chr(i)]:
				area += req[chr(i)]
			else:
				area += given[chr(i)]
	print(area)


import sys
n = input()
m = input()
N = dict()
M = dict()
for k in set(n):
	N.update({k: n.count(k)})
for k in set(m):
	M.update({k: m.count(k)})
S = 0
for k in M:
	if k in N:
		if N[k] >= M[k]:
			S += M[k]
		else:
			S += N[k]
	else:
		print(-1)
		return
print(S)


(a, b) = [{}, {}]
for i in input():
	if i not in a:
		a[i] = 0
	a[i] += 1
for i in input():
	if i not in b:
		b[i] = 0
	b[i] += 1
ans = 0
for i in b:
	if i not in a:
		ans = -1
		break
	ans += min(b[i], a[i])
print(ans)


def game():
	n = input()
	m = input()
	nlist = []
	mlist = []
	for i in range(len(n)):
		nlist.append(n[i])
	for i in range(len(m)):
		mlist.append(m[i])
	counter = 0
	for i in range(len(m)):
		if not m[i] in n:
			print(-1)
			return 1
	for i in range(len(m)):
		if m[i] in nlist:
			counter += 1
			mlist[i:i + 1] = []
			nlist[nlist.index(m[i])] = []
	print(counter)
game()


l1 = list(input())
l2 = list(input())
d1 = {}
d2 = {}
for i in l1:
	try:
		d1[i] += 1
	except:
		d1[i] = 1
for i in l2:
	try:
		d2[i] += 1
	except:
		d2[i] = 1
ans = 0
for i in d2:
	try:
		ans += min(d1[i], d2[i])
	except:
		print(-1)
		exit()
print(ans)


have = input()
required = input()
have_dict = {}
required_dict = {}
for char in have:
	if char not in have_dict:
		have_dict[char] = 0
	have_dict[char] += 1
for char in required:
	if char not in required_dict:
		required_dict[char] = 0
	required_dict[char] += 1
ans = 0
for c in required_dict:
	if c not in have_dict:
		print(-1)
		exit()
	elif required_dict[c] == have_dict[c]:
		ans += have_dict[c]
	elif required_dict[c] < have_dict[c]:
		ans += required_dict[c]
	elif required_dict[c] > have_dict[c]:
		ans += have_dict[c]
print(ans)


our_list_1 = list(map(str, input()))
our_list_3 = list(map(str, input()))
our_list_2 = list(set(our_list_3))
output = 0
for i in range(len(our_list_2)):
	if our_list_2[i] not in our_list_1:
		print(-1)
		break
	output += min(our_list_3.count(our_list_2[i]), our_list_1.count(our_list_2[i]))
	if i == len(our_list_2) - 1:
		print(output)


(n, m) = (input(), input())
(lis1, lis2, res) = ([], [], 0)
s = 'abcdefghijklmnopqrstuvwxyz'
for ch in s:
	lis1.append(n.count(ch))
	lis2.append(m.count(ch))
for i in range(26):
	if lis2[i] > 0 and lis1[i] == 0:
		print('-1')
		exit()
	if lis1[i] >= lis2[i]:
		res += lis2[i]
	else:
		res += lis1[i]
print(res)


def int_map(i=None):
	if not i:
		i = input()
	return map(int, i.split(' '))
res = 0
n = input()
m = input()
for i in range(97, 123):
	if n.count(chr(i)) == 0 and m.count(chr(i)) != 0:
		print(-1)
		exit()
	else:
		res += min(n.count(chr(i)), m.count(chr(i)))
if res == 0:
	print(-1)
else:
	print(res)


n = input()
m = input()

def f(n, m):
	an = [0] * 26
	am = [0] * 26
	for i in n:
		an[ord(i) - 97] += 1
	for j in m:
		am[ord(j) - 97] += 1
	c = 0
	for x in range(26):
		if am[x] != 0 and an[x] == 0:
			return -1
		elif am[x] > an[x]:
			c += an[x]
		else:
			c += am[x]
	return c
print(f(n, m))


import collections
import sys
import itertools
N = list(input().strip())
M = list(input().strip())
available_colors = collections.Counter(N)
pieces = collections.Counter(M)
ans = 0
best = 0
for color in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']:
	if color not in available_colors and color in pieces:
		print(-1)
		exit()
	ans += min(available_colors[color], pieces[color])
print(max(ans, best))


n = input()
m = input()
dn = dict()
dm = dict()
for i in n:
	if i not in dn:
		dn[i] = 1
	else:
		dn[i] += 1
for i in m:
	if i not in dm:
		dm[i] = 1
	else:
		dm[i] += 1
area = 0
for c in dm:
	if c not in dn:
		area = -1
		break
	elif dn[c] > dm[c]:
		area += dm[c]
	else:
		area += dn[c]
print(area)


from collections import Counter
a = list(input())
d = list(input())
fuck = set(a)
tlepausechamp = set(d)
ac = Counter(a)
dc = Counter(d)
ans = 0
f = 1
for i in tlepausechamp:
	if i not in fuck:
		print(-1)
		f = 0
		break
	if ac[i] >= dc[i]:
		ans += dc[i]
	else:
		ans += ac[i]
if f == 1:
	print(ans)


from collections import Counter
cin = input
s = Counter(cin())
t = Counter(cin())
cnt = 0
for i in t:
	if s[i]:
		cnt += min(s[i], t[i])
	else:
		print(-1)
		break
else:
	print(cnt)


colour = input()
new_colour = input()
sum = 0
k = 0
list = []
for i in new_colour:
	if i not in list:
		list += i
for i in list:
	a = colour.count(i)
	b = new_colour.count(i)
	if a > b:
		sum += b
	else:
		sum += a
	if i not in colour:
		k += 1
if k > 0:
	print(-1)
else:
	print(sum)


from sys import stdin
n = input()
m = input()
cnt = 0
if set(n).intersection(set(m)) == set(m):
	n_alphabet = [0] * 26
	m_alphabet = [0] * 26
	for i in range(len(n)):
		p = ord(n[i]) - 97
		n_alphabet[p] += 1
	for i in range(len(m)):
		q = ord(m[i]) - 97
		m_alphabet[q] += 1
	for i in range(26):
		if n_alphabet[i] <= m_alphabet[i]:
			cnt += n_alphabet[i]
		else:
			cnt += m_alphabet[i]
	print(cnt)
else:
	print('-1')


import sys
a = input()
b = input()
output = 0
for i in 'abcdefghijklmnopqrstuvwxyz':
	output += min(a.count(i), b.count(i))
	if b.count(i) > 0 and a.count(i) == 0:
		output = -1
		print(output)
		sys.exit()
print(-1 if output == 0 else output)


a = input()
b = input()
arr = [0] * 26
brr = [0] * 26
ans = 0
for i in a:
	arr[ord(i) - 97] += 1
for i in b:
	brr[ord(i) - 97] += 1
for i in range(26):
	if arr[i] == 0 and brr[i] != 0:
		print(-1)
		ans = -1
		break
	elif arr[i] <= brr[i]:
		ans += arr[i]
	else:
		ans += brr[i]
if ans > 0:
	print(ans)


a = input()
b = input()
d1 = {}
d2 = {}
for i in range(len(a)):
	if a[i] not in d1:
		d1[a[i]] = 1
	else:
		d1[a[i]] += 1
for i in range(len(b)):
	if b[i] not in d2:
		d2[b[i]] = 1
	else:
		d2[b[i]] += 1
cnt = 0
flag = True
for i in d2:
	if i in d1:
		if d1[i] >= d2[i]:
			cnt += min(d1[i], d2[i])
		else:
			cnt += d1[i]
	else:
		flag = False
		print('-1')
		exit(0)
if cnt == 0:
	print(-1)
else:
	print(cnt)


s = input()
g = input()
hs1 = [0] * 26
hs2 = [0] * 26
for i in range(len(s)):
	hs1[ord(s[i]) - ord('a')] += 1
for i in range(len(g)):
	hs2[ord(g[i]) - ord('a')] += 1
fl = 0
an = 0
for i in range(26):
	if hs2[i] != 0 and hs1[i] == 0:
		fl = 1
		break
	an += min(hs1[i], hs2[i])
if fl == 1:
	print(-1)
else:
	print(an)


import sys
colors = input()
finish_colors = input()
result = 0
differnt_finish_colors = set(finish_colors)
tested_colors = []
for color in differnt_finish_colors:
	if not color in tested_colors:
		if not colors.count(color):
			print('-1')
			return
		else:
			result += min([colors.count(color), finish_colors.count(color)])
print(result)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
a = input()
b = input()
aC = Counter(a)
bC = Counter(b)
ans = 0
for i in bC:
	if aC[i] == 0:
		print(-1)
		exit()
	if bC[i] <= aC[i]:
		ans += bC[i]
	else:
		ans += aC[i]
print(ans)


def garland(a, b):
	ans = 0
	for i in set(b):
		mini = min(a.count(i), b.count(i))
		if mini == 0:
			return -1
		ans += mini
	return ans
a = input()
b = input()
print(garland(a, b))


import sys
n = input()
m = input()
x = {}
y = {}
ans = 0
for i in n:
	if i not in x:
		x[i] = 0
	x[i] += 1
for i in m:
	if i not in y:
		y[i] = 0
	y[i] += 1
for i in y:
	if i not in x:
		print(-1)
		sys.exit()
	ans += min(x[i], y[i])
print(ans)


n = input()
d = {}
for i in n:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
n = input()
z = {}
for i in n:
	if i in z:
		z[i] += 1
	else:
		z[i] = 1
c = 0
for i in list(z.keys()):
	if i in d:
		if d[i] >= z[i]:
			c += z[i]
		else:
			c += d[i]
	else:
		print(-1)
		exit()
print(c)


import re
import inspect
from sys import argv, exit

def rstr():
	return input()

def rstrs(splitchar=' '):
	return [i for i in input().split(splitchar)]

def rint():
	return int(input())

def rints(splitchar=' '):
	return [int(i) for i in rstrs(splitchar)]

def varnames(obj, namespace=globals()):
	return [name for name in namespace if namespace[name] is obj]

def pvar(var, override=False):
	prnt(varnames(var), var)

def prnt(*args, override=False):
	if '-v' in argv or override:
		print(*args)
pq = []

def penq(s):
	if not isinstance(s, str):
		s = str(s)
	pq.append(s)

def pdump():
	s = '\n'.join(pq).encode()
	os.write(1, s)
s1 = [c for c in rstr()]
s2 = [c for c in rstr()]
counts1 = [len([c for c in s1 if ord(c) == ch]) for ch in range(ord('a'), ord('z') + 1)]
counts2 = [len([c for c in s2 if ord(c) == ch]) for ch in range(ord('a'), ord('z') + 1)]
total = 0
for (c1, c2) in zip(counts1, counts2):
	if c2 != 0 and c1 == 0:
		print('-1')
		exit(0)
	if c2 > c1:
		ans = c1
	else:
		ans = c2
	total += ans
print(total)


has = input()
need = input()
(A, B) = ([0] * 26, [0] * 26)
for i in has:
	A[ord(i) - 97] += 1
for i in need:
	B[ord(i) - 97] += 1
result = 0
for i in range(26):
	if not A[i] and B[i]:
		result = -1
		break
	else:
		result += min(A[i], B[i])
print(result)


from sys import stdin, stdout
from os import path
rd = lambda : stdin.readline().strip()
wr = stdout.write
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
import time
x = rd()
y = rd()
(c, d) = (set(x), set(y))
if d - c:
	print(-1)
else:
	counter = 0
	for i in d:
		counter += min(x.count(i), y.count(i))
	print(counter)


s = input()
t = input()
ds = {}
for i in s:
	if i in ds:
		ds[i] += 1
	else:
		ds[i] = 1
dt = {}
for i in t:
	if i in dt:
		dt[i] += 1
	else:
		dt[i] = 1
s = set(s)
t = set(t)
r = 0
for i in t:
	if i not in s:
		print(-1)
		exit()
	else:
		r += min(ds[i], dt[i])
print(r)


n = input()
m = input()
N = {}
for c in n:
	if c in N:
		N[c] += 1
	else:
		N[c] = 1
M = {}
for c in m:
	if c in M:
		M[c] += 1
	else:
		M[c] = 1
S = 0
for (color, count) in list(M.items()):
	if color not in N:
		S = -1
		break
	else:
		S += min(count, N[color])
print(S)


from collections import Counter
a = list(input())
b = list(input())
d1 = Counter(a)
c = 0
d2 = Counter(b)
for i in d2:
	if i in d1:
		if d1[i] < d2[i]:
			c += d1[i]
		else:
			c += d2[i]
	else:
		c = 0
		break
if c == 0:
	print(-1)
else:
	print(c)


n = input()
m = input()
li_n = [0] * 26
li_m = [0] * 26
for x in n:
	li_n[ord(x) - 97] += 1
for y in m:
	li_m[ord(y) - 97] += 1
ans = 0
for i in range(26):
	if li_m[i] != 0 and li_n[i] == 0:
		ans = -1
		break
	ans += min(li_m[i], li_n[i])
print(ans)


have = input()
want = input()
c = True
area = 0
for i in want:
	if have.count(i) == 0:
		c = False
if c:
	done = []
	for i in want:
		if i not in done:
			if have.count(i) <= want.count(i):
				area += have.count(i)
				done.append(i)
			else:
				area += want.count(i)
				done.append(i)
	print(area)
else:
	print(-1)


from collections import Counter
import sys
a = input()
b = input()
d = Counter(a)
k = 0
for i in b:
	if i not in d:
		print('-1')
		sys.exit()
	elif d[i] != 0:
		d[i] = d[i] - 1
		k = k + 1
print(k)


n = input().rstrip()
m = input().rstrip()
cnt1 = [0] * 26
cnt2 = [0] * 26
for i in n:
	cnt1[ord(i) - ord('a')] += 1
for i in m:
	cnt2[ord(i) - ord('a')] += 1
res = 0
for i in range(26):
	a1 = cnt1[i]
	a2 = cnt2[i]
	if a1 == 0 and a2 != 0:
		print(-1)
		exit()
	res += min(a1, a2)
print(res)


s1 = input()
s2 = input()
ar1 = [0] * 26
ar2 = [0] * 26
for i in s1:
	ar1[ord(i) - 97] += 1
for i in s2:
	ar2[ord(i) - 97] += 1
add = 0
b = True
for i in range(0, 26):
	if ar2[i] <= ar1[i]:
		add += ar2[i]
	elif ar2[i] > 0 and ar1[i] > 0:
		add += ar1[i]
	else:
		b = False
		break
if b == True:
	print(add)
else:
	print('-1')


a = {}
for c in input():
	if c not in a:
		a[c] = 0
	a[c] += 1
b = {}
for c in input():
	if c not in b:
		b[c] = 0
	b[c] += 1
res = 0
for c in b:
	if c not in a:
		print(-1)
		exit()
	res += min(a[c], b[c])
print(res)


n = str(input())
m = str(input())
nl = list(n)
ml = list(m)
ms = set(ml)
ans = 0
for i in ms:
	a = n.count(i)
	b = m.count(i)
	if a == 0 or b == 0:
		ans = -1
		break
	else:
		ans += min(a, b)
print(ans)


s = input()
s1 = input()
dic = {}
dic1 = {}
for i in s:
	if i not in dic:
		dic[i] = 1
	else:
		dic[i] += 1
c = 0
f = 0
for i in s1:
	if i not in dic:
		f = 1
		break
	if i not in dic1:
		dic1[i] = 1
	else:
		dic1[i] += 1
if f == 1:
	print(-1)
else:
	for i in dic1.keys():
		c += min(dic1[i], dic[i])
	print(c)


s = input()
t = input()
a = [0] * 26
b = [0] * 26
for i in s:
	a[ord(i) - ord('a')] += 1
for i in t:
	b[ord(i) - ord('a')] += 1
k = 0
for i in range(26):
	if b[i] > 0:
		if a[i] > 0:
			k += min(a[i], b[i])
		else:
			print(-1)
			exit()
print(k)


import sys
from collections import Counter
n = input()
m = input()
(x, y) = (Counter(), Counter())
for i in n:
	x[i] += 1
for i in m:
	y[i] += 1
ans = 0
for i in y:
	if x[i] == 0:
		print(-1)
		sys.exit()
	ans += min(x[i], y[i])
print(ans)


s1 = list(input())
s2 = list(input())
x = set(s1)
y = set(s2)
ans = 0
for i in y:
	a = min(s1.count(i), s2.count(i))
	if a == 0:
		print(-1)
		exit()
	ans += a
print(ans)


h = list(input())
n = list(input())
failed = False
have = {}
need = {}
area = 0
for i in range(0, len(h)):
	if h[i] in have.keys():
		have[h[i]] += 1
	else:
		have[h[i]] = 1
for i in range(0, len(n)):
	if n[i] in need.keys():
		need[n[i]] += 1
	else:
		need[n[i]] = 1
for n in need:
	if n not in have.keys():
		failed = True
		break
	elif need[n] > have[n]:
		area += have[n]
	else:
		area += need[n]
if failed:
	print(-1)
else:
	print(area)


string1 = input()
string2 = input()
n = 0
dic1 = {}
dic2 = {}
for i in range(len(string1)):
	if not string1[i] in dic1.keys():
		dic1[string1[i]] = 1
	else:
		dic1[string1[i]] += 1
for i in range(len(string2)):
	if not string2[i] in dic2.keys():
		if not string2[i] in dic1.keys():
			print(-1)
			raise SystemExit
		else:
			dic2[string2[i]] = 1
	else:
		dic2[string2[i]] += 1
for i in dic2.keys():
	if dic1[i] > dic2[i]:
		n += dic2[i]
	else:
		n += dic1[i]
print(n)


n = input()
m = input()
b = list(set(m))
count = 0
d1 = 0
for i in range(len(b)):
	a = n.count(b[i])
	d = m.count(b[i])
	if a == 0:
		d1 = 1
		break
	else:
		count += min(a, d)
if d1 == 1:
	print(-1)
else:
	print(count)


n = input()
m = input()
ans = 0
given = [0] * 26
reach = [0] * 26
for i in n:
	given[ord(i) - 97] += 1
for i in m:
	reach[ord(i) - 97] += 1
for i in range(26):
	if reach[i] > 0 and given[i] == 0:
		ans = -1
		break
	ans += min(given[i], reach[i])
print(ans)


import math
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
n = input()
m = input()
N = [i for i in n]
M = [i for i in m]
x = 0
for i in set(m):
	if i not in set(n):
		print(-1)
		exit()
for i in N:
	if i in M:
		x += 1
		M.remove(i)
print(x)


from collections import Counter
a = Counter(input())
b = Counter(input())
c = 0
for (k, v) in b.items():
	if k not in a:
		print(-1)
		exit(0)
	c += min(v, a.get(k, 0))
print(c)


k1 = input()
k2 = input()
hash1 = {}
hash2 = {}
for i in k1:
	try:
		hash1[i]
	except:
		hash1[i] = 1
	else:
		hash1[i] += 1
for i in k2:
	try:
		hash2[i]
	except:
		hash2[i] = 1
	else:
		hash2[i] += 1
flag = 0
count = 0
for i in hash2.keys():
	try:
		hash1[i]
	except:
		flag = 1
		break
	else:
		if hash1[i] >= hash2[i]:
			count += hash2[i]
		else:
			count += hash1[i]
if flag == 0:
	print(count)
else:
	print(-1)


from collections import Counter
have = str(input())
need = str(input())
have_count = dict(Counter(have))
need_count = dict(Counter(need))
need_list = need_count.keys()
ans = 0
for i in need_list:
	if i not in have_count.keys():
		ans = -1
		break
	else:
		ans = ans + min(need_count[i], have_count[i])
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
s = input()
t = input()
d = {}
for c in s:
	d[c] = d.get(c, 0) + 1
cnt = 0
d1 = {}
for c in t:
	d1[c] = d1.get(c, 0) + 1
for k in d1:
	if d.get(k, -1) == -1:
		print(-1)
		exit()
	cnt += min(d1.get(k, 0), d.get(k, 0))
print(cnt if cnt else -1)
endtime = time.time()


def count(s):
	c = [0] * 26
	for t in s:
		c[ord(t) - ord('a')] += 1
	return c
c1 = count(input())
c2 = count(input())
valid = True
result = 0
for i in range(26):
	if c2[i] > 0 and c1[i] == 0:
		valid = False
	result += min(c1[i], c2[i])
if not valid:
	print(-1)
else:
	print(result)


import collections as c
n = input()
t = input()
e = c.Counter(n)
d = c.Counter(t)
x = []
f = 0
for i in set(d):
	if i in set(e):
		continue
		f = 0
	else:
		f = 1
		break
if f == 0:
	for i in d:
		x.append(str(i))
	count = 0
	for i in x:
		if d[i] < e[i]:
			count += d[i]
		else:
			count += e[i]
	print(count)
else:
	print(-1)


s = input().strip()
m = input().strip()
c1 = [0] * 26
c2 = [0] * 26
for i in s:
	c1[ord(i) - ord('a')] += 1
for i in m:
	c2[ord(i) - ord('a')] += 1
ans = 0
for i in range(26):
	if c1[i] == 0 and c2[i] != 0:
		print(-1)
		return
	ans += min(c1[i], c2[i])
print(ans)


l1 = list(str(input()))
l2 = list(str(input()))
c = []
z = []
l1 = sorted(l1)
l2 = sorted(l2)
for i in l1:
	if i not in c:
		c.append(i)
for i in l2:
	if i not in z:
		z.append(i)
ck = 0
while ck < len(z):
	if z[ck] not in c:
		ck = len(z)
	ck += 1
fin = len(l1)
if ck == len(z) + 1:
	print(-1)
else:
	for i in range(len(c)):
		if l1.count(c[i]) - l2.count(c[i]) > 0:
			fin = fin - (l1.count(c[i]) - l2.count(c[i]))
	print(fin)


from collections import Counter
s = list(input())
t = list(input())
d1 = Counter(s)
d2 = Counter(t)
f = 1
for i in d2:
	if d1[i] == 0:
		f = 0
if f:
	ans = 0
	for i in d2:
		if d2[i] <= d1[i]:
			ans += d2[i]
		else:
			ans += d1[i]
	print(ans)
else:
	print(-1)


a = input()
b = input()
s = 0
ok = True
for i in range(27):
	c = chr(ord('a') + i)
	aa = a.count(c)
	bb = b.count(c)
	m = min(a.count(c), b.count(c))
	if aa == 0 and bb != 0:
		ok = False
	s = s + m
if not ok:
	print(-1)
else:
	print(s)


from collections import Counter as c
a = c(list(input()))
b = c(list(input()))
ans = 0
for i in b:
	if i in a:
		ans += min(b[i], a[i])
	else:
		print(-1)
		exit(0)
print(ans)


s = input()
t = input()
from collections import Counter
(ds, dt) = (Counter(), Counter())
for i in s:
	ds[i] += 1
for i in t:
	dt[i] += 1
ans = 0
for i in dt:
	if ds[i] == 0:
		print(-1)
		exit()
	ans += min(ds[i], dt[i])
print(ans)


from collections import Counter
paperPieces = Counter(input())
garlandPieces = Counter(input())
area = 0
for color in garlandPieces.keys():
	if color not in paperPieces:
		area = -1
		break
	else:
		paperCount = paperPieces[color]
		garlandPieceCount = garlandPieces[color]
		if paperCount >= garlandPieceCount:
			area += garlandPieceCount
		else:
			area += paperCount
print(area)


s1 = list(str(input()))
s2 = list(str(input()))
d1 = {}
d2 = {}
p = 0
c = 0
for i in range(len(s1)):
	if s1[i] not in d1:
		d1[s1[i]] = 1
	else:
		d1[s1[i]] += 1
for i in range(len(s2)):
	if s2[i] not in d2:
		d2[s2[i]] = 1
	else:
		d2[s2[i]] += 1
for i in d2.keys():
	if i not in d1.keys():
		p = 1
	elif d1[i] >= d2[i]:
		c += d2[i]
	else:
		c += d1[i]
if p == 1:
	print(-1)
else:
	print(c)


from collections import Counter
has = input()
n = len(has)
need = input()
m = len(need)
a = {}
b = {}
area = 0
for i in has:
	a[i] = a.get(i, 0) + 1
for i in need:
	b[i] = b.get(i, 0) + 1
if len(b) > len(a):
	print(-1)
else:
	flag = 0
	for i in range(m):
		if a.get(need[i], -1) == -1:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		k = 0
		for i in b:
			if a[i] >= b[i]:
				area += b[i]
			if a[i] < b[i]:
				area += a[i] / b[i] * b[i]
		print(int(area))


from collections import Counter
n = input()
k = input()
k1 = Counter(n)
k2 = Counter(k)
c = 0
flag = True
for i in k2:
	if i not in k1:
		flag = False
		break
	elif k1[i] >= k2[i]:
		c += k2[i]
	else:
		c += k1[i]
if flag == False:
	print(-1)
else:
	print(c)


n = sorted(list(input()))
k = sorted(list(input()))
a = {}
count = 0
flag = True
for i in k:
	if i in n:
		if i not in a:
			c = n.count(i)
			b = k.count(i)
			if c >= b:
				count += b
			else:
				count += c
			a[i] = 1
	else:
		flag = False
		break
if flag:
	print(count)
else:
	print(-1)


n = input()
m = input()
d1 = {}
d2 = {}
for i in n:
	if d1.get(i) == None:
		d1[i] = 1
	else:
		d1[i] += 1
for i in m:
	if d2.get(i) == None:
		d2[i] = 1
	else:
		d2[i] += 1
k = 1
sum = 0
for i in d2:
	if d1.get(i) != None:
		if d2[i] > d1[i]:
			sum += d1[i]
		else:
			sum += d2[i]
	else:
		k = 0
		break
if k == 0:
	print(-1)
else:
	print(sum)


def start():
	x = input()
	y = input()
	u = {}
	for i in x:
		try:
			u[i] += 1
		except:
			u[i] = 1
	v = {}
	for i in y:
		try:
			v[i] += 1
		except:
			v[i] = 1
	ans = 0
	for (i, j) in v.items():
		try:
			ans += min(0, u[i] - v[i]) + v[i]
		except:
			print(-1)
			exit()
	print(ans)
tc = 1
while tc:
	start()
	tc = tc - 1


import collections as cl
s = cl.Counter(input())
p = cl.Counter(input())
if not set(p.keys()).issubset(set(s.keys())):
	print(-1)
else:
	print(sum([min(s[c], p[c]) for c in p.keys()]))


n = input()
m = input()
n = ''.join(sorted(n))
m = ''.join(sorted(m))
fst = {}
snd = {}
for i in n:
	fst[ord(i) - ord('a')] = n.count(i)
for i in m:
	snd[ord(i) - ord('a')] = m.count(i)
sum = 0
for (k, v) in snd.items():
	try:
		if fst[k]:
			if snd[k]:
				sum += min(fst[k], snd[k])
	except KeyError:
		sum = 0
		break
if sum:
	print(sum)
else:
	print(-1)


n = input()
m = input()
s = set(m)
area = 0
for i in s:
	a1 = n.count(i)
	a2 = m.count(i)
	if a1 == 0:
		area = -1
		break
	elif a1 >= a2:
		area += a2
	else:
		area += a1
print(area)


n = str(input())
m = str(input())
dn = {}
dm = {}
for i in n:
	if i not in dn:
		dn[i] = 1
	else:
		dn[i] += 1
for i in m:
	if i not in dm:
		dm[i] = 1
	else:
		dm[i] += 1
f = ans = 0
for i in dm:
	if i not in dn:
		f = 1
		break
	elif dm[i] > dn[i]:
		ans += dn[i]
	else:
		ans += dm[i]
if f == 1:
	print(-1)
else:
	print(ans)


class CodeforcesTask408BSolution:

	def __init__(self):
		self.result = ''
		self.p = ''
		self.g = ''

	def read_input(self):
		self.p = input()
		self.g = input()

	def process_task(self):
		cnt1 = [0] * 26
		cnt2 = [0] * 26
		for c in self.p:
			cnt1[ord(c) - 123] += 1
		for c in self.g:
			cnt2[ord(c) - 123] += 1
		area = 0
		can = True
		for x in range(26):
			if cnt2[x] and (not cnt1[x]):
				can = False
				break
			area += min(cnt1[x], cnt2[x])
		if can:
			self.result = str(area)
		else:
			self.result = '-1'

	def get_result(self):
		return self.result
Solution = CodeforcesTask408BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import sys
from collections import Counter

def fmax(n, m):
	cn = Counter(n)
	cm = Counter(m)
	for i in cm:
		if cn[i] == 0:
			return -1
	ta = 0
	if len(n) <= len(m):
		for i in cm:
			ta = ta + min(cn[i], cm[i])
	if len(n) > len(m):
		for i in cm:
			ta = ta + min(cn[i], cm[i])
	return ta
input = sys.stdin.read()
data = list(map(str, input.split()))
n = data[0]
m = data[1]
print(fmax(n, m))


a = input()
b = input()
t = []
r = []
total = 0
flag = 0
for i in range(26):
	t.append(b.count(chr(97 + i)))
for i in range(26):
	r.append(a.count(chr(97 + i)))
for i in range(26):
	if t[i] != 0:
		if r[i] == 0:
			flag = 1
			break
		total = total + min(t[i], r[i])
if total == 0 or flag == 1:
	print(-1)
else:
	print(total)


from collections import defaultdict
s1 = input()
s2 = input()
dict1 = defaultdict(int)
dict2 = defaultdict(int)
for i in s1:
	dict1[i] += 1
for i in s2:
	dict2[i] += 1
ss = 0
f = 0
for i in dict2:
	k = min(dict2[i], dict1[i])
	if k > 0:
		ss += k
	else:
		f = 1
		break
if f == 0:
	print(ss)
else:
	print(-1)


s = input()
m = input()
ns = len(s)
nm = len(m)
smark = []
cnt = 0
for i in range(ns):
	smark.append(1)
for i in range(nm):
	ch = 0
	for j in range(ns):
		if m[i] == s[j]:
			ch = 1
			if smark[j] == 1:
				smark[j] = 0
				cnt = cnt + 1
				break
	if ch == 0:
		break
if ch == 0:
	print(-1)
else:
	print(cnt)


import fileinput
num_args = 2
for arg in range(num_args):
	if arg == 0:
		n_seq = input()
	else:
		m_seq = input()
n_letter_counts = {}
m_letter_counts = {}
for ltr in n_seq:
	if ltr in n_letter_counts:
		continue
	else:
		n_letter_counts[ltr] = n_seq.count(ltr)
for l in m_seq:
	if l in m_letter_counts:
		continue
	else:
		m_letter_counts[l] = m_seq.count(l)
total_area = 0
for cnt in m_letter_counts:
	if cnt in n_letter_counts:
		if n_letter_counts[cnt] >= 1:
			if n_letter_counts[cnt] >= m_letter_counts[cnt]:
				total_area += int(m_letter_counts[cnt])
			else:
				total_area += int(n_letter_counts[cnt])
	else:
		total_area = -1
		break
print(total_area)


s = str(input())
d = str(input())
a = sorted(s)
b = sorted(d)
c = set(b)
f = set(a)
di = {}
sum = 0
count = 0
for i in c:
	if i in f:
		count = count + 1
for i in c:
	if b.count(i) < a.count(i):
		di[i] = b.count(i)
	elif b.count(i) > a.count(i):
		di[i] = a.count(i)
	else:
		di[i] = a.count(i)
for (k, v) in di.items():
	sum = sum + v
if sum == 0 or count != len(c):
	print(-1)
else:
	print(sum)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
given = input()
want = input()
mydict1 = dict()
mydict2 = dict()
for i in given:
	mydict1[i] = mydict1.get(i, 0) + 1
for i in want:
	mydict2[i] = mydict2.get(i, 0) + 1
ans = 0
for i in mydict2:
	if i not in mydict1:
		print(-1)
		exit()
	else:
		ans += min(mydict1[i], mydict2[i])
print(ans)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
a = list(input())
b = list(input())
x = set(a)
y = set(b)
if 1 - y.issubset(x):
	print(-1)
	exit()
d = dict.fromkeys(b, 0)
d1 = dict.fromkeys(b, 0)
for i in range(max(len(a), len(b))):
	try:
		d[a[i]] += 1
	except:
		pass
	try:
		d1[b[i]] += 1
	except:
		pass
ans = 0
for (i, j) in zip(d.values(), d1.values()):
	ans += min(i, j)
print(ans)


n = list(input())
m = list(input())
ns = {}
ms = {}
for i in n:
	if not ns.get(i):
		ns[i] = 0
	ns[i] += 1
for i in m:
	if not ms.get(i):
		ms[i] = 0
	ms[i] += 1
count = 0
bad = False
for c in ms:
	if not ns.get(c):
		count = -1
		break
	count += min(ns[c], ms[c])
print(count)


n = []
m = []
n[0:] = input()
m[0:] = input()
m_unique = list(set(m))
area = 0
for i in m_unique:
	if i not in n:
		area = -1
		break
	area += m.count(i) if m.count(i) <= n.count(i) else n.count(i)
print(area)


from collections import Counter
C = lambda : Counter(input())
(s, t) = (C(), C())
x = sum((min(s[ch], t[ch]) for ch in s))
print(x if x and set(s) >= set(t) else -1)


s = input().rstrip()
g = input().rstrip()
p = dict()
for i in s:
	if i in p:
		p[i] += 1
	else:
		p[i] = 1
d = dict()
for i in g:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
s1 = set()
g1 = set()
for i in s:
	s1.add(i)
for i in g:
	g1.add(i)
flag = 0
for i in g1:
	if i in s1:
		pass
	else:
		flag = 1
		break
if flag == 1:
	print(-1)
	exit()
count = 0
for i in d:
	if p[i] >= d[i]:
		count += d[i]
	else:
		count += p[i]
print(count)


n = list(input())
m = list(input())
s1 = set(n)
s2 = set(m)
if s2.issubset(s1):
	s2 = list(s2)
	a = 0
	for i in range(len(s2)):
		if n.count(s2[i]) >= m.count(s2[i]):
			a = a + m.count(s2[i])
		else:
			a = a + n.count(s2[i])
	print(a)
else:
	print(-1)


a = input()
b = input()
ans = 0
for c in 'abcdefghijklmnopqrstuvwxyz':
	if a.count(c) == 0 and b.count(c) == 0:
		continue
	if a.count(c) == 0 and b.count(c) > 0:
		print(-1)
		exit(0)
	ans = ans + min(a.count(c), b.count(c))
print(ans)


n = input()
m = input()
i = 0
a = 0
while i < len(m):
	if not m[i] in n:
		print(-1)
		a = -1
		break
	i = i + 1
i = 0
if a != -1:
	while i < len(m):
		if m[i] in n:
			adet = n.count(m[i])
			n = n.replace(m[i], '') + (adet - 1) * m[i]
			a = a + 1
		i = i + 1
	print(a)


a = input()
b = input()
ans = 0
for i in range(ord('a'), ord('z') + 1):
	num1 = sum((ord(j) == i for j in a))
	num2 = sum((ord(j) == i for j in b))
	ans += min(num1, num2)
	if num2 > 0 and num1 == 0:
		print(-1)
		break
else:
	print(ans)


a = str(input())
b = str(input())
ar = [0] * 26
for c in a:
	ar[ord(c) - 97] += 1
count = 0
ok = 0
for c in b:
	if ar[ord(c) - 97] > 0:
		ar[ord(c) - 97] -= 1
		count += 1
		if ar[ord(c) - 97] == 0:
			ar[ord(c) - 97] = -1
	elif ar[ord(c) - 97] == 0:
		ok = 1
print(count) if count > 0 and ok == 0 else print(-1)