import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.lang.management.MemoryType;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.security.cert.CollectionCertStoreParameters;
import java.util.*;
import java.util.function.Function;

public class Main {

    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

        public static void main (String[]args) throws IOException {
        Scanner in = new Scanner(System.in);
        try(PrintWriter or = new PrintWriter(System.out)) {

           char[]a=in.next().toCharArray();
           char[]b =in.next().toCharArray();
           int []aa= new int[26];
           int[]bb =new int[26];
            for (int i = 0; i < a.length; i++) {
                aa[a[i]-'a']++;
            }
            for (int i = 0; i < b.length; i++) {
                bb[b[i]-'a']++;
            }
            int ans=0;
            for (int i = 0; i < 26; i++) {
                if (aa[i]==0&&bb[i]>0){
                    or.println(-1);

                    return;
                }
                ans+=Math.min(aa[i],bb[i]);
            }
            or.println(ans==0?-1:ans);

        }
    }

    static int getlen(int r,int l,int a){
        return (r-l+1+1)/(a+1);
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Pair  {
    int first, second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

}

class Tempo {

    int num;
    int index;

    public Tempo(int num, int index) {
        this.num = num;
        this.index = index;
    }
}


import java.util.*;

public class Garland {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String g = sc.next();
		sc.close();
		List<Character> l = new ArrayList<>();
		List<Character> gar = new ArrayList<>();

		for(int i=0; i<a.length(); i++)
		{
			l.add(a.charAt(i));
		}

		for(int i=0; i<g.length(); i++)
		{
			gar.add(g.charAt(i));
		}

		int count=0;
		for(char x: gar)
		{
			if(l.contains(x))
			{
				count++;
				int t = l.indexOf(x);
				l.remove(t);
			}
		}

		if(count==0)
		{
			System.out.println("-1");
		}
		else
		{
			System.out.println(count);
		}
	}

}


import java.util.*;

public class Garland {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String g = sc.next();
		sc.close();
		List<Character> l = new ArrayList<>();
		List<Character> gar = new ArrayList<>();

		for(int i=0; i<a.length(); i++)
		{
			l.add(a.charAt(i));
		}

		for(int i=0; i<g.length(); i++)
		{
			gar.add(g.charAt(i));
		}

		int count = 0;
		int flag = 0;
		for(char x: gar)
		{
			if(!l.contains(x))
			{
				flag=1;
				break;
			}
		}

		for(char x: gar)
		{
			if(l.contains(x))
			{
				count++;
				int t = l.indexOf(x);
				l.remove(t);
			}
		}

		if(flag==1)
		{
			System.out.println("-1");
		}
		else
		{
			System.out.println(count);
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

public class Garland {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String a = sc.next();
		String g = sc.next();
		List<Character> l = new ArrayList<>();
		List<Character> gar = new ArrayList<>();

		for(int i=0; i<a.length(); i++)
		{
			l.add(a.charAt(i));
		}

		for(int i=0; i<g.length(); i++)
		{
			gar.add(g.charAt(i));
		}

		int count = 0;
		int flag = 0;
		for(char x: gar)
		{
			if(!l.contains(x))
			{
				flag=1;
				break;
			}
		}

		for(char x: gar)
		{
			if(l.contains(x))
			{
				count++;
				int t = l.indexOf(x);
				l.remove(t);
			}
		}

		if(flag==1)
		{
			System.out.println("-1");
		}
		else
		{
			System.out.println(count);
		}
	}

}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;
public class Main
{
 static Map<Character,Integer> createMap(String a)
  {
   Map<Character,Integer> map=new HashMap<>();
   for(int i=0;i<a.length();i++)
        {
            char c=a.charAt(i);

            if(!map.containsKey(c))
             map.put(c,1);
            else
             map.replace(c,map.get(c)+1);
        }
    return map;
  }
public static void main(String args[]) throws java.lang.Exception
     {

       Scanner sc=new Scanner(System.in);
       PrintWriter out=new PrintWriter(System.out);
       String a=sc.next();
       String b=sc.next();

        Map<Character,Integer> aa=createMap(a);
        Map<Character,Integer> bb=createMap(b);

        Set<Map.Entry<Character,Integer>> bbb=bb.entrySet();
        int sum=0;
        for(Map.Entry<Character,Integer> data : bbb)
          {
             char c=data.getKey();
             if(aa.containsKey(c))
               {
                 int need=data.getValue();
                 int a6e=aa.get(c);
                 sum+=Math.min(need,a6e);
               }
          }
          out.println(sum==0 ? "-1" : sum);

       out.flush();
     }
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;
public class Main
{
 static Map<Character,Integer> createMap(String a)
  {
   Map<Character,Integer> map=new HashMap<>();
   for(int i=0;i<a.length();i++)
        {
            char c=a.charAt(i);

            if(!map.containsKey(c))
             map.put(c,1);
            else
             map.replace(c,map.get(c)+1);
        }
    return map;
  }
public static void main(String args[]) throws java.lang.Exception
     {

       Scanner sc=new Scanner(System.in);
       PrintWriter out=new PrintWriter(System.out);
       String a=sc.next();
       String b=sc.next();

        Map<Character,Integer> aa=createMap(a);
        Map<Character,Integer> bb=createMap(b);

        Set<Map.Entry<Character,Integer>> bbb=bb.entrySet();
        int sum=0;
        for(Map.Entry<Character,Integer> data : bbb)
          {
             char c=data.getKey();
             if(aa.containsKey(c))
               {
                 int need=data.getValue();
                 int a6e=aa.get(c);
                 sum+=Math.min(need,a6e);
               }
              else
               {
                   sum=0;
                   break;
               }
          }
          out.println(sum==0 ? "-1" : sum);

       out.flush();
     }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		///
		int[] cnt1 = new int[26], cnt2 = new int[26];
		char[] c=  f.next().toCharArray();
		for(char cc : c) cnt1[cc-'a']++;
		c=  f.next().toCharArray();
		for(char cc : c) cnt2[cc-'a']++;
		int a = 0;
		for(int i = 0; i < 26; i++) {
			if(cnt1[i] == 0 && cnt2[i] != 0) {
				a = -1;
				break;
			} else a += Math.min(cnt1[i], cnt2[i]);
		}
		out.println(a);
///
		out.flush();
	}
///
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        string a, b;

        int x[256] = {}, y[256] = {};
        long long ans = 1;
        cin >> a >> b;

        for(auto &it : a)
                ++x[it];
        for(auto &it : b)
                ++y[it];

        for(int i = 'a'; i <= 'z'; ++i) {
                if(x[i] == 0 && y[i] > 0) {
                        cout << -1;
                        return 0;
                }
                if(x[i] >= y[i] && y[i] > 0) ans *= y[i];
        }

        cout << ans;

        return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        string a, b;

        int x[256] = {}, y[256] = {};
        long long ans = 1;
        cin >> a >> b;

        for(auto &it : a)
                ++x[it];
        for(auto &it : b)
                ++y[it];

        for(int i = 'a'; i <= 'z'; ++i) {
                if(x[i] == 0 && y[i] > 0) {
                        cout << -1;
                        return 0;
                }
                if(x[i] >= y[i] && y[i] > 0) {
                        int each = x[i] / y[i];
                        ans *= each * y[i];
                }
        }

        cout << ans;

        return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        string a, b;

        int x[256] = {}, y[256] = {};
        long long ans = 1;
        cin >> a >> b;

        for(auto &it : a)
                ++x[it];
        for(auto &it : b)
                ++y[it];

        for(int i = 'a'; i <= 'z'; ++i) {
                if(x[i] == 0 && y[i] > 0) {
                        cout << -1;
                        return 0;
                }
                if(x[i] >= y[i] && y[i] > 0) {
                        int each = x[i] / y[i];
                        ans *= each * y[i];
                }
                else if(y[i] > x[i]) ans *= x[i];
        }

        cout << ans;

        return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        string a, b;

        int x[256] = {}, y[256] = {};
        long long ans = 0;
        cin >> a >> b;

        for(auto &it : a)
                ++x[it];
        for(auto &it : b)
                ++y[it];

        for(int i = 'a'; i <= 'z'; ++i) {

                if(x[i] == 0 && y[i] > 0) {
                        cout << -1;
                        return 0;
                }
                if(y[i] == 0) continue;
                if(y[i] > x[i]) ans += x[i];
                if(x[i] == y[i]) ans += x[i];
                if(x[i] > y[i]) ans += y[i];
        }

        cout << ans;

        return 0;
}


//JSD
#include<algorithm>
#define ll long long
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int has1[26]={0};
	int has2[26]={0};
	for(int i=0;i<a.length();i++){
		has1[a[i]-'a']++;
	}
	for(int i=0;i<b.length();i++){
		has2[b[i]-'a']++;
	}
	vector<int> inter;
	int sum=0;
	for(int i=0;i<26;i++)	{
		sum+=(min(has1[i],has2[i]));
	}
	if(sum==0)
		cout<<"-1\n";
	else
		cout<<sum<<"\n";
	return 0;
}


//JSD
#include<algorithm>
#define ll long long
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int has1[26]={0};
	int has2[26]={0};
	for(int i=0;i<a.length();i++){
		has1[a[i]-'a']++;
	}
	for(int i=0;i<b.length();i++){
		has2[b[i]-'a']++;
	}
	vector<int> inter;
	int sum=0;
	bool res=1;
	for(int i=0;i<26;i++)	{
		if(has1[i]==0 and has2[i]>0)
			res=0;
		sum+=(min(has1[i],has2[i]));
	}
	if(!res)
		cout<<"-1\n";
	else
		cout<<sum<<"\n";
	return 0;
}


//JSD
#include<algorithm>
#define ll long long
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int has1[26]={0};
	int has2[26]={0};
	for(int i=0;i<a.length();i++){
		has1[a[i]-'a']++;
	}
	for(int i=0;i<b.length();i++){
		has2[b[i]-'a']++;
	}
	vector<int> inter;
	int sum=0;
	bool res=1;
	for(int i=0;i<26;i++)	{
		if(has1[i]==0 and has2[i]>0)
			res=0;
		sum+=(min(has1[i],has2[i]));
	}
	if(res)
		cout<<"-1\n";
	else
		cout<<sum<<"\n";
	return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define MAX 30000
#define pi 3.1415926536
#define mp make_pair
#define ss second
#define ff first
#define ll long long

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //std::cout << std::fixed << std::setprecision(6);

    char s1[1010]; char s2[1010];
    cin>>s1>>s2;

    int f1[26]={0}; int f2[26]={0};

    for (int i=0; i<strlen(s1); i++)
    {
        f1[(int)s1[i]-(int)'a']++;
    }

    for (int i=0; i<strlen(s2); i++)
    {
        f2[(int)s2[i]-(int)'a']++;
    }

    int flag=0;
    int ans=0;
    for (int i=0; i<26; i++)
    {
        if (f2[i])
        {
            ans+=min(f2[i],f1[i]);
        }
    }

    if (ans)
    cout<<ans<<endl;

    else
    cout<<-1<<endl;

}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define MAX 30000
#define pi 3.1415926536
#define mp make_pair
#define ss second
#define ff first
#define ll long long

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //std::cout << std::fixed << std::setprecision(6);

    char s1[1010]; char s2[1010];
    cin>>s1>>s2;

    int f1[26]={0}; int f2[26]={0};

    for (int i=0; i<strlen(s1); i++)
    {
        f1[(int)s1[i]-(int)'a']++;
    }

    for (int i=0; i<strlen(s2); i++)
    {
        f2[(int)s2[i]-(int)'a']++;
    }

    int flag=0;
    int ans=0;
    for (int i=0; i<26; i++)
    {
        if (f2[i] && !f1[i])
        {
            flag=1;
            break;
        }

        if (f2[i])
        {
            ans+=min(f2[i],f1[i]);
        }
    }

    if (!flag){
    if (ans)
    cout<<ans<<endl;

    else
    cout<<-1<<endl;
    }
    else
    cout<<-1<<endl;

}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define MOD 998244353
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define show(x) cout<<#x<<" = "<<(x)<<" "
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define EN cout<<endl;
#define fn(i,n) for (ll i=0; i<n; i++)
#define fone(i,n) for (int i=1; i<=n; i++)
#define fl(i,a,b) for (int i=a; i<=b; i++)
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
#define MAX 1001009
#define all(v) v.begin(), v.end()
#define int long long
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; }
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
int n; int a[MAX];
signed main()
{
    string s,t; cin>>s>>t;

    int n = s.length(); int m=s.length();

    int f2[26]={0}; int f1[26]={0};

    fn(i,n)
    {
        f1[(int)s[i]-(int)'a']++;
    }
    fn(i, m)
    {
        f2[(int)t[i]-(int)'a']++;
    }
    int ans = 0;
    bool c=false;
    fn(i,26)
    {
        if (f1[i]^f2[i]==1)
            c=false;
        ans+=min(f1[i],f2[i]);
    }
    if(!c)
        cout<<-1;
    else
        cout<<ans<<endl;

}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define MOD 998244353
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define show(x) cout<<#x<<" = "<<(x)<<" "
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define EN cout<<endl;
#define fn(i,n) for (ll i=0; i<n; i++)
#define fone(i,n) for (int i=1; i<=n; i++)
#define fl(i,a,b) for (int i=a; i<=b; i++)
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
#define MAX 1001009
#define all(v) v.begin(), v.end()
#define int long long
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; }
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
int n; int a[MAX];
signed main()
{
    string s,t; cin>>s>>t;

    int n = s.length(); int m=s.length();

    int f2[26]={0}; int f1[26]={0};

    fn(i,n)
    {
        f1[(int)s[i]-(int)'a']++;
    }
    fn(i, m)
    {
        f2[(int)t[i]-(int)'a']++;
    }
    int ans = 0;
    bool c=false;
    fn(i,26)
    {
        if (f2[i] && !f1[i])
            c=false;
        ans+=min(f1[i],f2[i]);
    }
    if(!c)
        cout<<-1;
    else
        cout<<ans<<endl;

}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define MOD 998244353
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define show(x) cout<<#x<<" = "<<(x)<<" "
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define EN cout<<endl;
#define fn(i,n) for (ll i=0; i<n; i++)
#define fone(i,n) for (int i=1; i<=n; i++)
#define fl(i,a,b) for (int i=a; i<=b; i++)
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
#define MAX 1001009
#define all(v) v.begin(), v.end()
#define int long long
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; }
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
int n; int a[MAX];
signed main()
{
    string s,t; cin>>s>>t;

    int n = s.length(); int m=s.length();

    int f2[26]={0}; int f1[26]={0};

    fn(i,n)
    {
        f1[(int)s[i]-(int)'a']++;
    }
    fn(i, m)
    {
        f2[(int)t[i]-(int)'a']++;
    }
    int ans = 0;
    fn(i,26)
    {
        ans+=min(f1[i],f2[i]);
    }
    if(!ans)
        cout<<-1;
    else
        cout<<ans<<endl;

}


using namespace std;
#include<bits/stdc++.h>
#define pb push_back
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define MOD 998244353
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define show(x) cout<<#x<<" = "<<(x)<<" "
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define EN cout<<endl;
#define fn(i,n) for (ll i=0; i<n; i++)
#define fone(i,n) for (int i=1; i<=n; i++)
#define fl(i,a,b) for (int i=a; i<=b; i++)
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
#define MAX 1001009
#define all(v) v.begin(), v.end()
#define int long long
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; }
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
int n; int a[MAX];
signed main()
{
    string s,t; cin>>s>>t;

    int n = s.length(); int m=s.length();

    int f2[26]={0}; int f1[26]={0};

    fn(i,n)
    {
        f1[(int)s[i]-(int)'a']++;
    }
    fn(i, m)
    {
        f2[(int)t[i]-(int)'a']++;
    }
    int ans = 0;
    bool c=false;
    fn(i,26)
    {
        if (f2[i] && !f2[i])
            c=false;
        ans+=min(f1[i],f2[i]);
    }
    if(!c)
        cout<<-1;
    else
        cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;ll r=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        if(mv[i]!=0 && nv[i]==0){
            cout<<"-1";
            return 0;
        }
        ll t=min(nv[i],mv[i]);
        if(t!=0)
            r=r+1;
        sum=sum+min(nv[i],mv[i]);
    }
    cout<<r;
    if(sum==0)
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        sum=sum+min(nv[i],mv[i]);
    }
    if(sum==0)
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;ll r=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        if(mv[i]!=0 && nv[i]==0){
            cout<<"-1";
            return 0;
        }
        ll t=min(nv[i],mv[i]);
        if(t!=0)
            r=r+1;
        sum=sum+min(nv[i],mv[i]);
    }
    //cout<<r;
    if(sum==0)
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;ll r=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        ll t=min(nv[i],mv[i]);
        if(t!=0)
            r=r+1;
        sum=sum+min(nv[i],mv[i]);
    }
    if(sum==0 || r==1)
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;ll r=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        ll t=min(nv[i],mv[i]);
        if(t!=0)
            r=r+1;
        sum=sum+min(nv[i],mv[i]);
    }
    if(sum==0 || (r==1 && m.size()!=1))
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<ll> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n,m;
    vi nv(26);
    vi mv(26);
    cin>>n;
    cin>>m;
    sort(n.begin(),n.end());
    sort(m.begin(),m.end());
    ll i=0;
    while(i<n.size()){
        ll a=count(n.begin(),n.end(),n[i]);
        ll index=int(n[i])-97;
        nv[index]=a;
        i=i+a;
    }
    i=0;
    while(i<m.size()){
        ll a=count(m.begin(),m.end(),m[i]);
        mv[int(m[i])-97]=a;
        i=i+a;
    }
    ll sum=0;
    for(i=0;i<26;i++){
        //cout<<mv[i]<<nv[i]<<" ";
        sum=sum+min(nv[i],mv[i]);
    }
    if(sum==0 || sum<m.size()/2)
        cout<<"-1";
    else
        cout<<sum;
    return 0;

}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[1010];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s1.size(); i++) {
		chk[s1[i] - 'a']++;
	}
	int cnt = 0;
	for (int i = 0; i < s2.size(); i++) {
		if (chk[s2[i] - 'a'] > 0) {
			cnt++;
			chk[s2[i] - 'a']--;
		}
		else{
		    printf("-1");
		    return 0;
		}
	}
	if (cnt == 0)printf("-1");
	else printf("%d", cnt);
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[1010];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s1.size(); i++) {
		chk[s1[i] - 'a']++;
	}
	int cnt = 0;
	for (int i = 0; i < s2.size(); i++) {
		if (chk[s2[i] - 'a'] > 0) {
			cnt++;
			chk[s2[i] - 'a']--;
		}
	}
	if (cnt == 0)printf("-1");
	else printf("%d", cnt);
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[1010];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s2.size(); i++) {
		chk[s1[i] - 'a']++;
	}
	int cnt = 0;
	for (int i = 0; i < s1.size(); i++) {
		if (chk[s2[i] - 'a'] > 0) {
			cnt++;
			chk[s2[i] - 'a']--;
		}
	}
	if (cnt == 0)printf("-1");
	else printf("%d", cnt);
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[1010];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s1.size(); i++) {
		chk[s1[i] - 'a']++;
	}
	int cnt = 0, w = 0;
	for (int i = 0; i < s2.size(); i++) {
		if (chk[s2[i] - 'a'] > 0) {
			cnt++;
			chk[s2[i] - 'a']--;
		}
		else {
			w++;
		}
	}
	if (s1.size() == w)printf("-1");
	else printf("%d", cnt);
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[30];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s2.size(); i++) {
		chk[s1[i] - '0']++;
	}
	int cnt = 0;
	for (int i = 0; i < s1.size(); i++) {
		if (chk[s2[i] - '0'] > 0) {
			cnt++;
			chk[s2[i] - '0']--;
		}
	}
	if (cnt == 0)printf("-1");
	else printf("%d", cnt);
	return 0;
}


#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
int n, m, k, arr[100010];
string s1, s2;
int chk[1010];
bool trig[1010];
int main() {
	cin >> s1 >> s2;
	for (int i = 0; i < s1.size(); i++) {
		chk[s1[i] - 'a']++;
	}
	int cnt = 0, w = 0;
	for (int i = 0; i < s2.size(); i++) {
		if (chk[s2[i] - 'a'] > 0) {
			cnt++;
			chk[s2[i] - 'a']--;
			trig[s2[i] - 'a'] = true;
		}
		else {
			if (!trig[s2[i] - 'a']) {
				printf("-1");
				return 0;
			}
		}
	}printf("%d", cnt);
	return 0;
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;

typedef long long int ll ;

#define FOR(i,a,n) for(ll i = a ; i < n ; i++)

//FrOm BeLoW.....

int solve()
{
    string s1 , s2 ; cin >> s1 >> s2 ;
    int alp1[26]={0} , alp2[26] ={0};
    FOR(i,0,s1.length())
    {
        alp1[s1[i] -'a']++ ;
    }
    FOR(i,0,s2.length())
    {
        alp2[s2[i] -'a']++ ;
    }
    bool al = true ;
    ll sum = 0 ;
    FOR(i,0,26)
    {
        if(alp1[i] <= alp2[i])
        {
            sum += alp1[i] ;
        }
        else
        {
            sum += alp2[i];
            al = false ;
        }
    }
    if(sum ==0) return cout << "-1" ,0;
    if(al)
    {if(sum -1 ==0) return cout << "-1" ,0;

        cout << sum-1;

    }
    else cout << sum ;

}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10)  ;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//fclose(stdin);fclose(stdout);

//CODE FROM BELOW

int t =1 ;
// cin >> t ;
while(t--)
{
    solve() ;
}

return 0 ;
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;

typedef long long int ll ;

#define FOR(i,a,n) for(ll i = a ; i < n ; i++)

//FrOm BeLoW.....

int solve()
{
    string s1 , s2 ; cin >> s1 >> s2 ;
    int alp1[26]={0} , alp2[26] ={0};
    FOR(i,0,s1.length())
    {
        alp1[s1[i] -'a']++ ;
    }
    FOR(i,0,s2.length())
    {
        alp2[s2[i] -'a']++ ;
    }

    ll sum = 0 ;
    FOR(i,0,26)
    {
        if(alp1[i] == 0 && alp2[i] !=0)
            return cout << "-1" , 0 ;
        else
        {
            sum += min(alp1[i],alp2[i]);
        }
    }

    cout << sum ;

}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10)  ;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//fclose(stdin);fclose(stdout);

//CODE FROM BELOW

int t =1 ;
// cin >> t ;
while(t--)
{
    solve() ;
}

return 0 ;
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;

typedef long long int ll ;

#define FOR(i,a,n) for(ll i = a ; i < n ; i++)

//FrOm BeLoW.....

int solve()
{
    string s1 , s2 ; cin >> s1 >> s2 ;
    int alp1[26]={0} , alp2[26] ={0};
    FOR(i,0,s1.length())
    {
        alp1[s1[i] -'a']++ ;
    }
    FOR(i,0,s2.length())
    {
        alp2[s2[i] -'a']++ ;
    }
    bool al = true ;
    ll sum = 0 ;
    FOR(i,0,26)
    {
        if(alp1[i] <= alp2[i])
        {
            sum += alp1[i] ;
        }
        else
        {
            sum += alp2[i];
            al = false ;
        }
    }
    if(sum ==0) return cout << "-1" ,0;
    if(al)
    {//if(sum -1 ==0) return cout << "-1" ,0;

        cout << sum-1;

    }
    else cout << sum ;

}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10)  ;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//fclose(stdin);fclose(stdout);

//CODE FROM BELOW

int t =1 ;
// cin >> t ;
while(t--)
{
    solve() ;
}

return 0 ;
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;

typedef long long int ll ;

#define FOR(i,a,n) for(ll i = a ; i < n ; i++)

//FrOm BeLoW.....

int solve()
{
    string s1 , s2 ; cin >> s1 >> s2 ;
    int alp1[26]={0} , alp2[26] ={0};
    FOR(i,0,s1.length())
    {
        alp1[s1[i] -'a']++ ;
    }
    FOR(i,0,s2.length())
    {
        alp2[s2[i] -'a']++ ;
    }
    bool al = true ;
    ll sum = 0 ;
    FOR(i,0,26)
    {
        if(alp1[i] <= alp2[i])
        {
            sum += alp1[i] ;
        }
        else
        {
            sum += alp2[i];
            al = false ;
        }
    }
    if(sum ==0) return cout << "-1" ,0;
    cout << sum ;

}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10)  ;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//fclose(stdin);fclose(stdout);

//CODE FROM BELOW

int t =1 ;
// cin >> t ;
while(t--)
{
    solve() ;
}

return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define endl              '\n'
#define all(x)            (x).begin(),(x).end()
#define pb                push_back
#define mk                make_pair
#define s                 second
#define f                 first
#define ll                long long
#define ld                long double
#define ull               unsigned long long
#define mod               1000000007
#define pi                3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	string s1,s2;   cin>>s1>>s2;
	ll arr1[26] = {0},arr2[26] ={0};
	for(int i = 0; i < s1.size() ; i++){
		arr1[s1[i] - 'a']++;
	}
	for(int i = 0; i < s2.size() ; i++){
		arr2[s2[i] - 'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 26 ; i++){
		if(arr1[i] != 0 && arr2[i] == 0){
			cout<<-1<<endl;
			return 0;
		}else{
    		ans += min(arr1[i],arr2[i]);
		}
	}
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define endl              '\n'
#define all(x)            (x).begin(),(x).end()
#define pb                push_back
#define mk                make_pair
#define s                 second
#define f                 first
#define ll                long long
#define ld                long double
#define ull               unsigned long long
#define mod               1000000007
#define pi                3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	string s1,s2;   cin>>s1>>s2;
	ll arr1[26] = {0},arr2[26] ={0};
	for(int i = 0; i < s1.size() ; i++){
		arr1[s1[i] - 'a']++;
	}
	for(int i = 0; i < s2.size() ; i++){
		arr2[s2[i] - 'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 26 ; i++){
		ans += min(arr1[i],arr2[i]);
	}
	if(ans == 0){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define endl              '\n'
#define all(x)            (x).begin(),(x).end()
#define pb                push_back
#define mk                make_pair
#define s                 second
#define f                 first
#define ll                long long
#define ld                long double
#define ull               unsigned long long
#define mod               1000000007
#define pi                3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	string s1,s2;   cin>>s1>>s2;
	ll arr1[26] = {0},arr2[26] ={0};
	for(int i = 0; i < s1.size() ; i++){
		arr1[s1[i] - 'a']++;
	}
	for(int i = 0; i < s2.size() ; i++){
		arr2[s2[i] - 'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 26 ; i++){
		if(arr1[i] == 0 && arr2[i] != 0){
			cout<<-1<<endl;
			return 0;
		}else{
    		ans += min(arr1[i],arr2[i]);
		}
	}
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define endl              '\n'
#define all(x)            (x).begin(),(x).end()
#define pb                push_back
#define mk                make_pair
#define s                 second
#define f                 first
#define ll                long long
#define ld                long double
#define ull               unsigned long long
#define mod               1000000007
#define pi                3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	string s1,s2;   cin>>s1>>s2;
	ll arr1[26] = {0},arr2[26] ={0};
	for(int i = 0; i < s1.size() ; i++){
		arr1[s1[i] - 'a']++;
	}
	for(int i = 0; i < s2.size() ; i++){
		arr2[s2[i] - 'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 26 ; i++){
		ans += min(arr1[i],arr2[i]);
	}
	if(ans){
    	cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define endl              '\n'
#define all(x)            (x).begin(),(x).end()
#define pb                push_back
#define mk                make_pair
#define s                 second
#define f                 first
#define ll                long long
#define ld                long double
#define ull               unsigned long long
#define mod               1000000007
#define pi                3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	string s1,s2;   cin>>s1>>s2;
	ll arr1[26] = {0},arr2[26] ={0};
	for(int i = 0; i < s1.size() ; i++){
		arr1[s1[i] - 'a']++;
	}
	for(int i = 0; i < s2.size() ; i++){
		arr2[s2[i] - 'a']++;
	}
	int ans = 0;
	for(int i = 0; i < 26 ; i++){
		ans += min(arr1[i],arr2[i]);
	}
	if(ans > 0){
    	cout<<ans<<endl;
	}else if(ans == 0){
		cout<<-1<<endl;
	}
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
   // freopen("input.txt", "r", stdin); // redirects standard input
  //freopen("output.txt", "w", stdout); // redirects standard output

 int i,p=0,t,n,m;;
 string s,k;
 cin>>s;
 cin>>k;
 n=s.length();
 m=k.length();
 int b[26]={0};
 int c[26]={0};
 if(n>=m)
 {
    t=n;

 }
 else
 {
    t=m;

 }

 for(i=0;i<t;i++)
 {
    if(i<n)
    {
    b[(s[i])-97]++;
    }
    if(i<m)
    {
       c[(k[i])-97]++;
    }
 }

 for(i=0;i<t;i++)
 {
    p=p+min(b[i],c[i]);
 }
 if(p>0)
 {
 cout<<p;
 }
 else
 {
    cout<<"-1";
 }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
   // freopen("input.txt", "r", stdin); // redirects standard input
  //freopen("output.txt", "w", stdout); // redirects standard output

 int i,p=0,t,n,m,d;
 string s,k;
 cin>>s;
 cin>>k;
 n=s.length();
 m=k.length();
 int b[26]={0};
 int c[26]={0};
 if(n>=m)
 {
    t=n;

 }
 else
 {
    t=m;

 }

 for(i=0;i<t;i++)
 {
    if(i<n)
    {
    b[(s[i])-97]++;
    }
    if(i<m)
    {
       c[(k[i])-97]++;
    }
 }

 for(i=0;i<26;i++)
 {
    if(c[i]>0 && b[i]==0)
    {
       d=1;
    }
    p=p+min(b[i],c[i]);
 }
 if(d==1)
 {
 cout<<"-1";
 }
 else if(p>0)
 {
    cout<<p;
 }
 else
 {
    cout<<"-1";
 }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
   // freopen("input.txt", "r", stdin); // redirects standard input
  //freopen("output.txt", "w", stdout); // redirects standard output

 int i,p=0,t,n,m;;
 string s,k;
 cin>>s;
 cin>>k;
 n=s.length();
 m=k.length();
 int b[26]={0};
 int c[26]={0};
 if(n>=m)
 {
    t=n;

 }
 else
 {
    t=m;

 }

 for(i=0;i<t;i++)
 {
    if(i<n)
    {
    b[(s[i])-97]++;
    }
    if(i<m)
    {
       c[(k[i])-97]++;
    }
 }

 for(i=0;i<26;i++)
 {
    p=p+min(b[i],c[i]);
 }
 if(p>0)
 {
 cout<<p;
 }
 else
 {
    cout<<"-1";
 }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
   // freopen("input.txt", "r", stdin); // redirects standard input
  //freopen("output.txt", "w", stdout); // redirects standard output

 int i,p=0,t,n,m,d=0;
 string s,k;
 cin>>s;
 cin>>k;
 n=s.length();
 m=k.length();
 int b[26]={0};
 int c[26]={0};
 if(n>=m)
 {
    t=n;

 }
 else
 {
    t=m;

 }

 for(i=0;i<t;i++)
 {
    if(i<n)
    {
    b[(s[i])-97]++;
    }
    if(i<m)
    {
       c[(k[i])-97]++;
    }
 }

 for(i=0;i<26;i++)
 {
    if(c[i]>0 && b[i]==0)
    {
       d++;
    }
    p=p+min(b[i],c[i]);
 }
 if(d>0)
 {
 cout<<"-1";
 }
 else if(p>0)
 {
    cout<<p;
 }
 else
 {
    cout<<"-1";
 }
}


#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9+7;

const int N = 1e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int a[26],b[26];
int32_t main(){

   string s,t;
   int sum=0;
   cin>>s>>t;

   for(int i=0;i<s.length();i++){
      a[s[i]-'a']++;
   }
   for(int i=0;i<t.length();i++){
      b[t[i]-'a']++;
   }

   for(int i=0;i<26;i++){
       sum+=(min(a[i],b[i]));
        if (b[i] > 0 && a[i] == 0) {
            cout << "-1";
            return 0;
        }
   }

   if(sum==0)
        cout<<-1;
    else
        cout<<sum;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9+7;

const int N = 1e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int a[26],b[26];
int32_t main(){

   string s,t;
   int sum=0;
   cin>>s>>t;

   for(int i=0;i<s.length();i++){
      a[s[i]-'a']++;
   }
   for(int i=0;i<s.length();i++){
      b[t[i]-'a']++;
   }

   for(int i=0;i<26;i++){
       sum+=(min(a[i],b[i]));
        if (b[i] > 0 && a[i] == 0) {
            cout << "-1";
            return 0;
        }
   }

   if(sum==0)
        cout<<"-1";
    else
        cout<<sum;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9+7;

const int N = 1e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int a[26],b[26];
int32_t main(){

   string s,t;
   int sum=0;
   cin>>s>>t;

   for(int i=0;i<s.length();i++){
      a[s[i]-'a']++;
   }
   for(int i=0;i<s.length();i++){
      b[t[i]-'a']++;
   }

   for(int i=0;i<26;i++){
        sum+=(min(a[i],b[i]));
   }

   if(sum==0)
        cout<<"-1";
    else
        cout<<sum;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9+7;

const int N = 1e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int a[26],b[26];
int32_t main(){

   string s,t;
   int sum=0;
   cin>>s>>t;

   for(int i=0;i<s.length();i++){
      a[s[i]-'a']++;
   }
   for(int i=0;i<s.length();i++){
      b[t[i]-'a']++;
   }

   for(int i=0;i<26;i++){
        if(a[i]>=b[i])
            sum+=1;
        else
            sum+=(min(a[i],b[i]));
   }

   if(sum==0)
        cout<<"-1";
    else
        cout<<sum;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;

int main() { _
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
    multiset <char> set1; multiset <char> set2; set <char> set3;;
    string a, b; cin >> a >> b;
    int count = 0;
    for(int i = 0; i < a.size(); i++){
        set1.insert(a[i]);
    }
    for(int i = 0; i < b.size(); i++){
        set2.insert(b[i]);
    }
    for(auto it = set2.begin(); it != set2.end(); it++){
        if(set1.find(*it) != set1.end()){
            if(set1.count(*it) > 1){
                count++; set1.erase(set1.find(*it));
            }else{
                set3.insert(*it);
            }
        }
    }
    if(count == 0 && set3.empty()){
        cout << -1 << endl;
    }else{
        cout << count + set3.size() << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;

int main() { _
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
    multiset <char> set1; multiset <char> set2; set <char> set3;;
    string a, b; cin >> a >> b;
    int count = 0;
    for(int i = 0; i < a.size(); i++){
        set1.insert(a[i]);
    }
    for(int i = 0; i < b.size(); i++){
        set2.insert(b[i]);
    }
    for(auto it = set2.begin(); it != set2.end(); it++){
        if(set1.find(*it) != set1.end()){
            if(set1.count(*it) > 1){
                count++; set1.erase(set1.find(*it));
            }else{
                set3.insert(*it);
            }
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << count + set3.size() << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;

int main() { _
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
    multiset <char> set1; multiset <char> set2; set <char> set3;;
    string a, b; cin >> a >> b;
    int count = 0;
    for(int i = 0; i < a.size(); i++){
        set1.insert(a[i]);
    }
    for(int i = 0; i < b.size(); i++){
        set2.insert(b[i]);
    }
    for(auto it = set2.begin(); it != set2.end(); it++){
        if(set1.find(*it) != set1.end()){
            if(set1.count(*it) > 1){
                count++; set1.erase(set1.find(*it));
            }else{
                set3.insert(*it);
            }
        }else{
            cout << -1 << endl;
        }
    }
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define debug(x) cout << (#x) << " " << (x) <<" "<< endl
#define debug2(x,y) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< endl
#define debug3(x,y,z) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< (#z) << " " << (z) << endl

#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define readwrite freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#define f(a, b, c) for(ll a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mii map<int, int>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mcii map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define cinvec(v) f(i, 0, v.size()) cin >> v[i];
#define printvec(v, n) for (auto e: ans) cout << e << " "; cout << endl;
#define pi acos(-1)
#define point complex<ld>
using namespace std;

const ll mod = 1e6 + 3;
int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll fact[1000001]; ll inv[1000001];
ll arr[1000007];
ll primes[100007];

ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

set<ll> GetDivisors(ll val){
    set<ll> st;
    f(i, 1, sqrt(val) + 1) if (val % i == 0) st.insert(i), st.insert(val / i);
    return st;
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
bool isPrime (ll n) {
    if (n <= 1)
        return false;

    for (int i = 2; i*i <=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
string findSmallestLexoWithoutDupilcates (string s) {
    int cnt[27];
    bool vis[27];
    for (int i=0; i<s.size(); i++) cnt[s[i]-'a']++;
    string ans="";
    for (int i=0; i<s.size(); i++){
        int x=s[i]-'a';
        cnt[x]--;
        if(vis[x]) continue;
        while (ans.size()>0 && s[i]<ans.back() && cnt[ans.back()-'a']>0){
            vis[ans.back()-'a']=false;
            ans.pop_back();
        }
        ans.push_back(s[i]);
        vis[x]=true;
    }
    return ans;
}
ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;
}

// Note: if there is a cycle, the size of the return will be less than n.
vector<int> topological_sort(const vector<vector<int>> &adj) {
    int n = int(adj.size());
    vector<int> in_degree(n, 0);
    vector<int> order;

    for (int i = 0; i < n; i++)
        for (int neighbor : adj[i])
            in_degree[neighbor]++;

    for (int i = 0; i < n; i++)
        if (in_degree[i] == 0)
            order.push_back(i);

    int current = 0;

    while (current < int(order.size())) {
        int node = order[current++];

        for (int neighbor : adj[node])
            if (--in_degree[neighbor] == 0)
                order.push_back(neighbor);
    }

    return order;
}

const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e4+ 7;
const ll llinf = INT64_MAX;
const int intinf = INT32_MAX;

//ll t, n, k, m, a, b, r, c, d, x, y, q, z;

int main() {
    MohamedMotaz

    string s, t;
    cin >> s >> t;

    mcii mp1, mp2;
    for (auto e: s) mp1[e]++;
    for (auto e: t) mp2[e]++;

    int ctr = 0;

    for (auto e: t){
        if (mp1[e]){
            ctr++;
            mp1[e]--;
        }else{
            return cout << -1, 0;
        }
    }

    if (!ctr) cout << -1; else cout << ctr;

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define debug(x) cout << (#x) << " " << (x) <<" "<< endl
#define debug2(x,y) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< endl
#define debug3(x,y,z) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< (#z) << " " << (z) << endl

#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define readwrite freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#define f(a, b, c) for(ll a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mii map<int, int>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mcii map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define cinvec(v) f(i, 0, v.size()) cin >> v[i];
#define printvec(v, n) for (auto e: ans) cout << e << " "; cout << endl;
#define pi acos(-1)
#define point complex<ld>
using namespace std;

const ll mod = 1e6 + 3;
int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll fact[1000001]; ll inv[1000001];
ll arr[1000007];
ll primes[100007];

ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

set<ll> GetDivisors(ll val){
    set<ll> st;
    f(i, 1, sqrt(val) + 1) if (val % i == 0) st.insert(i), st.insert(val / i);
    return st;
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
bool isPrime (ll n) {
    if (n <= 1)
        return false;

    for (int i = 2; i*i <=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
string findSmallestLexoWithoutDupilcates (string s) {
    int cnt[27];
    bool vis[27];
    for (int i=0; i<s.size(); i++) cnt[s[i]-'a']++;
    string ans="";
    for (int i=0; i<s.size(); i++){
        int x=s[i]-'a';
        cnt[x]--;
        if(vis[x]) continue;
        while (ans.size()>0 && s[i]<ans.back() && cnt[ans.back()-'a']>0){
            vis[ans.back()-'a']=false;
            ans.pop_back();
        }
        ans.push_back(s[i]);
        vis[x]=true;
    }
    return ans;
}
ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;
}

// Note: if there is a cycle, the size of the return will be less than n.
vector<int> topological_sort(const vector<vector<int>> &adj) {
    int n = int(adj.size());
    vector<int> in_degree(n, 0);
    vector<int> order;

    for (int i = 0; i < n; i++)
        for (int neighbor : adj[i])
            in_degree[neighbor]++;

    for (int i = 0; i < n; i++)
        if (in_degree[i] == 0)
            order.push_back(i);

    int current = 0;

    while (current < int(order.size())) {
        int node = order[current++];

        for (int neighbor : adj[node])
            if (--in_degree[neighbor] == 0)
                order.push_back(neighbor);
    }

    return order;
}

const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e4+ 7;
const ll llinf = INT64_MAX;
const int intinf = INT32_MAX;

//ll t, n, k, m, a, b, r, c, d, x, y, q, z;

int main() {
    MohamedMotaz

    string s, t;
    cin >> s >> t;

    mcii mp1, mp2;
    for (auto e: s) mp1[e]++;
    for (auto e: t) mp2[e]++;

    int ctr = 0;

    for (auto e: t){
        if (mp1[e]){
            ctr++;
            mp1[e]--;
        }
    }

    if (!ctr) cout << -1; else cout << ctr;

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vi vector<int>
#define vs vector<string>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mci map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define pi acos(-1)
#define point complex<ld>
using namespace std;

const ll mod = 1e9 + 7;
int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll fact[1000001]; ll inv[1000001];
ll primes[100007];
ll arr[1000007];
ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;

}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

sll GetDivisors(ll val){
    sll st;
    f(i, 1, sqrt(val) + 1) if (val % i == 0) st.insert(i), st.insert(val / i);
    return st;
}
string findSmallestLexoWithoutDupilcates (string s) {
    int cnt[27];
    bool vis[27];
    for (int i=0; i<s.size(); i++) cnt[s[i]-'a']++;
    string ans="";
    for (int i=0; i<s.size(); i++){
        int x=s[i]-'a';
        cnt[x]--;
        if(vis[x]) continue;
        while (ans.size()>0 && s[i]<ans.back() && cnt[ans.back()-'a']>0){
            vis[ans.back()-'a']=false;
            ans.pop_back();
        }
        ans.push_back(s[i]);
        vis[x]=true;
    }
    return ans;
}
const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e4 + 7;
const ll inf = 1e18 + 5;

ll t, n, m, a, b, x, y;

int main() {
    MohamedMotaz
    string a, b;
    cin >> a >> b;
    mcll mp1, mp2;
    bool cant = false;
    int counter = 0;
    for (auto e: a) mp1[e]++;
    for (auto e: b) mp2[e]++;
    for (auto e: mp2) counter += min(mp1[e.first], e.second), (!mp1[e.first]) ? cant = true: 0;
    if (cant) return cout << -1, 0;
    (counter) ? cout << counter: cout << -1;

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define debug(x) cout << (#x) << " " << (x) <<" "<< endl
#define debug2(x,y) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< endl
#define debug3(x,y,z) cout << (#x) << " " << (x) <<" "<< (#y) << " " << (y) <<" "<< (#z) << " " << (z) << endl

#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define readwrite freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#define f(a, b, c) for(ll a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mii map<int, int>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mcii map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define cinvec(v) f(i, 0, v.size()) cin >> v[i];
#define printvec(v, n) for (auto e: ans) cout << e << " "; cout << endl;
#define pi acos(-1)
#define point complex<ld>
using namespace std;

const ll mod = 1e6 + 3;
int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll fact[1000001]; ll inv[1000001];
ll arr[1000007];
ll primes[100007];

ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

set<ll> GetDivisors(ll val){
    set<ll> st;
    f(i, 1, sqrt(val) + 1) if (val % i == 0) st.insert(i), st.insert(val / i);
    return st;
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
bool isPrime (ll n) {
    if (n <= 1)
        return false;

    for (int i = 2; i*i <=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
string findSmallestLexoWithoutDupilcates (string s) {
    int cnt[27];
    bool vis[27];
    for (int i=0; i<s.size(); i++) cnt[s[i]-'a']++;
    string ans="";
    for (int i=0; i<s.size(); i++){
        int x=s[i]-'a';
        cnt[x]--;
        if(vis[x]) continue;
        while (ans.size()>0 && s[i]<ans.back() && cnt[ans.back()-'a']>0){
            vis[ans.back()-'a']=false;
            ans.pop_back();
        }
        ans.push_back(s[i]);
        vis[x]=true;
    }
    return ans;
}
ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;
}

// Note: if there is a cycle, the size of the return will be less than n.
vector<int> topological_sort(const vector<vector<int>> &adj) {
    int n = int(adj.size());
    vector<int> in_degree(n, 0);
    vector<int> order;

    for (int i = 0; i < n; i++)
        for (int neighbor : adj[i])
            in_degree[neighbor]++;

    for (int i = 0; i < n; i++)
        if (in_degree[i] == 0)
            order.push_back(i);

    int current = 0;

    while (current < int(order.size())) {
        int node = order[current++];

        for (int neighbor : adj[node])
            if (--in_degree[neighbor] == 0)
                order.push_back(neighbor);
    }

    return order;
}

const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e4+ 7;
const ll llinf = INT64_MAX;
const int intinf = INT32_MAX;

//ll t, n, k, m, a, b, r, c, d, x, y, q, z;

int main() {
    MohamedMotaz

    string s, t;
    cin >> s >> t;

    mcii mp1, mp2;
    for (auto e: s) mp1[e]++;
    for (auto e: t) mp2[e]++;

    int ctr = 0;

    for (auto e: mp2){
        if (!mp1[e.first]){
            return cout << -1, 0;
        }else ctr += min(mp1[e.first], e.second);
    }

    if (!ctr) cout << -1; else cout << ctr;

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vi vector<int>
#define vs vector<string>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mci map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define pi acos(-1)
#define point complex<ld>
using namespace std;

const ll mod = 1e9 + 7;
int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll fact[1000001]; ll inv[1000001];
ll primes[100007];
ll arr[1000007];
ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;

}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

sll GetDivisors(ll val){
    sll st;
    f(i, 1, sqrt(val) + 1) if (val % i == 0) st.insert(i), st.insert(val / i);
    return st;
}
string findSmallestLexoWithoutDupilcates (string s) {
    int cnt[27];
    bool vis[27];
    for (int i=0; i<s.size(); i++) cnt[s[i]-'a']++;
    string ans="";
    for (int i=0; i<s.size(); i++){
        int x=s[i]-'a';
        cnt[x]--;
        if(vis[x]) continue;
        while (ans.size()>0 && s[i]<ans.back() && cnt[ans.back()-'a']>0){
            vis[ans.back()-'a']=false;
            ans.pop_back();
        }
        ans.push_back(s[i]);
        vis[x]=true;
    }
    return ans;
}
const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e4 + 7;
const ll inf = 1e18 + 5;

ll t, n, m, a, b, x, y;

int main() {
    MohamedMotaz
    string a, b;
    cin >> a >> b;
    mcll mp1, mp2;
    int counter = 0;
    for (auto e: a) mp1[e]++;
    for (auto e: b) mp2[e]++;
    for (auto e: mp2) counter += min(mp1[e.first], e.second);
    (counter) ? cout << counter: cout << -1;

}


#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define sort(v)       sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
//#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000

using namespace std;
int spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<int> getFactorization(int x)
{
    vector<int> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
int gcd( int a, int b )
{
	if(b==0)
	{
	     return a;
	}
	else
	{
	     return gcd( b, a%b );
	}
}
int lcm (int a, int b)
{
return (a*b)/gcd(a,b);
}
int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n%2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int modInverse(int A,int M)
{
    return modularExponentiation(A,M-2,M);
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	t=1;
	//cin>>t;
	while(t--)
	{
  		string n,m;
  		cin>>n>>m;
  		map<char,int> mp1;
  		map<char,int> mp2;
  		rep(i,0,n.size())
  		mp1[n[i]]++;
  		rep(i,0,m.size())
  		mp2[m[i]]++;
  		set<char> s(all(m));
  		string str(all(s));
  		//cout<<str<<endl;
  		int c(0);
  		rep(i,0,str.size())
  		{
  			if(mp1[str[i]]==0)
  				{
  					cout<<"-1";
  					return 0;
  				}
  			else
  			{
  				c+=min(mp1[str[i]],mp2[str[i]]);
  			}
  		}
  		cout<<c;

	}

}


#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define sort(v)       sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
//#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000

using namespace std;
int spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<int> getFactorization(int x)
{
    vector<int> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
int gcd( int a, int b )
{
	if(b==0)
	{
	     return a;
	}
	else
	{
	     return gcd( b, a%b );
	}
}
int lcm (int a, int b)
{
return (a*b)/gcd(a,b);
}
int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n%2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int modInverse(int A,int M)
{
    return modularExponentiation(A,M-2,M);
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	t=1;
	//cin>>t;
	while(t--)
	{
  		string n,m;
  		cin>>n>>m;
  		map<char,int> mp1;
  		map<char,int> mp2;
  		rep(i,0,n.size())
  		mp1[n[i]]++;
  		rep(i,0,m.size())
  		mp2[m[i]]++;
  		set<char> s(all(m));
  		string str(all(s));
  		//cout<<str<<endl;
  		int c(0);
  		rep(i,0,str.size())
  		{
  			if(mp1[str[i]]==0)
  				{
  					cout<<"-1";
  					return 0;
  				}
  			else
  			{
  				c+=min(mp1[str[i]],mp2[str[i]]);
  			}
  		}
  		cout<<c;
	}
}


#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;

string a, b ;
int ans = 0;
int x[26], y[26] ;

signed main() {

	cin >> a >> b ;

	int n1 = a.length(int) ;
	int n2 = b.length(int) ;

	for(int i = 0; i < n1; i++){
		x[(a[i] - 'a')]++ ;
	}

	for(int i = 0; i < n2; i++){
		y[(b[i] - 'a')]++ ;
	}

	for(int i = 0; i < 26; i++){

		if(x[i] == 0 && y[i] != 0){
			cout << "-1" << endl ;
			return 0 ;

		ans += min(x[i], y[i]) ;

		}
	}

	cout << ans << endl ;

	return 0;
}


#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;

string a, b ;
int ans = 0;
int x[26], y[26] ;

signed main() {

	cin >> a >> b ;

	int n1 = a.length() ;
	int n2 = b.length() ;

	for(int i = 0; i < n1; i++){
		x[(a[i] - 'a')]++ ;
	}

	for(int i = 0; i < n2; i++){
		y[(b[i] - 'a')]++ ;
	}

	for(int i = 0; i < 26; i++){

		//cout << x[i] << " " ;

		if(x[i] == 0 && y[i] != 0){
			cout << "-1" << endl ;
			return 0 ;
		}
		ans += min(x[i], y[i]) ;
	}

	//cout << endl ;

	cout << ans << endl ;

	return 0;
}


#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;

string a, b ;
int ans = 0;

signed main() {

	cin >> a >> b ;

	int n1 = a.length() ;
	int n2 = b.length() ;
	int x[76], y[76] ;

	for(int i = 0; i < n1; i++){
		x[(a[i] - '0')]++ ;
	}

	for(int i = 0; i < n2; i++){
		y[(b[i] - '0')]++ ;
	}

	for(int i = 0; i < 76; i++){
		ans += min(x[i], y[i]) ;
	}

	if(ans > 0) cout << ans << endl ;
	else cout << "-1" << endl ;

	return 0;
}


#include <bits/stdc++.h>
#define int long long
const int INF = (int)1e18 + 18 ;
const int maxx = (int) 1e6 + 6 ;
using namespace std ;

string a, b ;
int ans = 0;
int x[26], y[26] ;

signed main() {

	cin >> a >> b ;

	int n1 = a.length() ;
	int n2 = b.length() ;

	for(int i = 0; i < n1; i++){
		x[(a[i] - 'a')]++ ;
	}

	for(int i = 0; i < n2; i++){
		y[(b[i] - 'a')]++ ;
	}

	for(int i = 0; i < 26; i++){

		if(x[i] == 0 && y[i] != 0){
			cout << "-1" << endl ;
			return 0 ;

		ans += min(x[i], y[i]) ;

		}
	}

	cout << ans << endl ;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = 256;
const int N = 1e6 + 555;
int cnt0[N], cnt[N];
void solve()
{
	string a, b;
	cin >> a >> b;
	rep(i, sz(a)) cnt0[a[i] - 'a']++;
	rep(i, sz(b)) cnt[b[i] - 'a']++;
	int sum = 0;
	rep(i, 26){
		sum += min(cnt[i], cnt0[i]);
		if(cnt0[i] && !cnt[i]){
			cout << -1;
			return;
		}
	}
	cout << sum;
}
int main()
{
	Red;
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = 256;
const int N = 1e6 + 555;
int cnt0[N], cnt[N];
void solve()
{
	string a, b;
	cin >> a >> b;
	rep(i, sz(a)) cnt0[a[i] - 'a']++;
	rep(i, sz(b)) cnt[b[i] - 'a']++;
	int sum = 0;
	rep(i, 26){
		sum += min(cnt[i], cnt0[i]);
	}
	if(!sum) cout << -1;
	else cout << sum;
}
int main()
{
	Red;
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = 256;
const int N = 1e6 + 555;
int cnt0[N], cnt[N];
void solve()
{
	string a, b;
	cin >> a >> b;
	rep(i, sz(a)) cnt0[a[i] - 'a']++;
	rep(i, sz(b)) cnt[b[i] - 'a']++;
	int sum = 0;
	rep(i, 26){
		sum += min(cnt[i], cnt0[i]);
		if(cnt[i] && !cnt0[i]){
			cout << -1;
			return;
		}
	}
	cout << sum;
}
int main()
{
	Red;
	solve();
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	unordered_map<char,int>mmap1,mmap2;
	for(int i = 0; i < s1.size(); i++)
		mmap1[s1[i]]++;
	for(int i = 0; i < s2.size(); i++)
		mmap2[s2[i]]++;
	int res = 0;
	for(char ch = 'a'; ch <= 'z'; ch++){
		if(mmap2[ch] > 0){
			if(mmap1[ch] >= mmap2[ch])
				res = res + mmap2[ch];
			else{
				if(mmap1[ch] > 0)
					res = res + 1;
			}
		}
	}
	if(res == 0)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	unordered_map<char,int>mmap1,mmap2;
	for(int i = 0; i < s1.size(); i++)
		mmap1[s1[i]]++;
	for(int i = 0; i < s2.size(); i++)
		mmap2[s2[i]]++;
	unordered_map<char,int> :: iterator it;
	int res = 0;
	for(it = mmap2.begin(); it != mmap2.end(); it++){
		int temp1 = mmap1[it->first];
		if(it->second < temp1)
			res = res + it->second;
		else
			res = res + temp1;
	}
	if(res == 0)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	unordered_map<char,int>mmap1,mmap2;
	for(int i = 0; i < s1.size(); i++)
		mmap1[s1[i]]++;
	for(int i = 0; i < s2.size(); i++)
		mmap2[s2[i]]++;
	int res = 0;
	for(char ch = 'a'; ch <= 'z'; ch++){
		if(mmap2[ch] > 0){
			if(mmap1[ch] >= mmap2[ch])
				res = res + mmap2[ch];
			else{
				if(mmap1[ch] > 0)
					res = res + mmap1[ch];
			}
		}
	}
	if(res == 0)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	unordered_map<char,int>mmap1,mmap2;
	for(int i = 0; i < s1.size(); i++)
		mmap1[s1[i]]++;
	for(int i = 0; i < s2.size(); i++)
		mmap2[s2[i]]++;
	int res = 0;
	for(char ch = 'a'; ch <= 'z'; ch++){
		if(mmap2[ch] > 0){
			if(mmap1[ch] == 0){
				res = -1;
				break;
			}
			else{
				if(mmap1[ch] >= mmap2[ch])
					res = res + mmap2[ch];
				else
					res = res + mmap1[ch];
			}
		}
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	unordered_map<char,int>mmap1,mmap2;
	for(int i = 0; i < s1.size(); i++)
		mmap1[s1[i]]++;
	for(int i = 0; i < s2.size(); i++)
		mmap2[s2[i]]++;
	int res = 0;
	for(char ch = 'a'; ch <= 'z'; ch++){
		if(mmap1[ch] < mmap2[ch])
			res = res + mmap1[ch];
		else
			res = res + mmap2[ch];
	}
	if(res == 0)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


#include<iostream>
#include<stack>
using namespace std;

int calculate(string s1,string s2,int i1,int i2){
	if(i1 == s1.size() || i2 == s2.size())
		return 0;
	else{
		if(s1[i1] == s2[i2]){
			return 1 + calculate(s1,s2,i1+1,i2+1);
		}
		else{
			int max1 = calculate(s1,s2,i1+1,i2);
			int max2 = calculate(s1,s2,i1,i2+1);
			if(max1 > max2)
				return max1;
			else
				return max2;
		}
	}
}

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	stack<char>ms1,ms2;
	for(int i = 0; i < s1.size(); i++)
		ms1.push(s1[i]);
	for(int i = 0; i < s2.size(); i++)
		ms2.push(s2[i]);
	int res = calculate(s1,s2,0,0);
	if(res == 0)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <fstream>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <utility>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef long long ll;

const int INF = 1000000000;
int N, A, B;
vi m, res;

void init()
{
 //   freopen("b.in", "r", stdin);
 //   freopen("b.out", "w", stdout);
}

void read()
{
	scanf("%d%d%d", &N, &A, &B);
	int t;
	m.clear();
	for (int i=0; i<N; i++)
	{
		scanf("%d", &t);
		m.push_back(t);
	}

}

void solve()
{
	res.clear();
	if (A==B)
	{
		for(int i=0; i<A; i++)
			res.push_back(1);
		for (int i=A; i<N; i++)
			res.push_back(2);
	}
	else if (A>B)
	{
		int cnt=0;
		bool fin=false;
		for (int i=0; i<m.size(); i++) res.push_back(1);
		for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==5) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==4) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==3) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==2) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==1) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
	}
	else
	{
		int cnt=0;
		bool fin=false;
		for (int i=0; i<m.size(); i++) res.push_back(2);
		for (int i=0; i<m.size(); i++)
		{
			if (m[i]==5) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==4) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==3) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==2) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==1) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
	}

}

void write()
{
	for(int i=0; i<res.size(); i++)
		printf("%d ", res[i]);

}

int main()
{
    init();
    read();
    solve();
    write();
    return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <fstream>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <utility>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef long long ll;

const int INF = 1000000000;
int N, A, B;
vi m, res;

void init()
{
//    freopen("b.in", "r", stdin);
//    freopen("b.out", "w", stdout);
}

void read()
{
	scanf("%d%d%d", &N, &A, &B);
	int t;
	m.clear();
	for (int i=0; i<N; i++)
	{
		scanf("%d", &t);
		m.push_back(t);
	}

}

void solve()
{
	res.clear();
	if (A==B)
	{
		for(int i=0; i<A; i++)
			res.push_back(1);
		for (int i=A; i<N; i++)
			res.push_back(2);
	}
	if (A>B)
	{
		int cnt=0;
		bool fin=false;
		for (int i=0; i<m.size(); i++) res.push_back(1);
		for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==5) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==4) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==3) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==2) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
		if (!fin) for (int i=m.size()-1; i>=0; i--)
		{
			if (m[i]==1) {res[i]=2; cnt++;}
			if (cnt==B) {fin=true; break;}
		}
	}
	else
	{
		int cnt=0;
		bool fin=false;
		for (int i=0; i<m.size(); i++) res.push_back(2);
		for (int i=0; i<m.size(); i++)
		{
			if (m[i]==5) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==4) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==3) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==2) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
		if (!fin) for (int i=0; i<m.size(); i++)
		{
			if (m[i]==1) {res[i]=1; cnt++;}
			if (cnt==A) {fin=true; break;}
		}
	}

}

void write()
{
	for(int i=0; i<res.size(); i++)
		printf("%d ", res[i]);

}

int main()
{
    init();
    read();
    solve();
    write();
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int n, a, b;
int mrk[100010];
int id[100010];
int ac[7][2];

bool cmp(int x, int y){
	return mrk[x] < mrk[y];
}

int main(){
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	for(int i = 0; i < n; i++)
		scanf("%d", &mrk[i]);
	for(int i = 0; i < n; i++)
		id[i] = i;
	sort(id, id + n, cmp);
	int t1 = 1, t2 = 2;
	if(a == b){
		for(int i = 0; i < a; i++){
			if(i) printf(" ");
			printf("1");
		}
		for(int i = a; i < n; i++){
			if(i) printf(" ");
			printf("2");
		}
	}
	else{
		if(a < b) {swap(a, b); swap(t1, t2);}
		for(int i = 0; i < a; i++)
			ac[mrk[id[i]]][t1]++;
		for(int i = a; i < n; i++)
			ac[mrk[id[i]]][t2]++;
		for(int i = 0; i < n; i++){
			if(i) putchar(' ');
			if(ac[mrk[i]][1]){
				printf("1"); ac[mrk[i]][1]--;
			}
			else printf("2");
		}
	}
	puts("");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int n, a, b;
int mrk[100010];
int id[100010], res[100010];

bool cmp(int x, int y){
	return mrk[x] < mrk[y];
}

int main(){
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	for(int i = 0; i < n; i++)
		scanf("%d", &mrk[i]);
	for(int i = 0; i < n; i++)
		id[i] = i;
	sort(id, id + n, cmp);
	if(a == b){
		for(int i = 0; i < a; i++){
			if(i) printf(" ");
			printf("1");
		}
		for(int i = a; i < n; i++){
			if(i) printf(" ");
			printf("2");
		}
	}
	else{
		int t1 = 1, t2 = 2;
		if(a < b) {swap(a, b); swap(t1, t2);}
		for(int i = 0; i < a; i++)
			res[id[i]] = t1;
		for(int i = a; i < n; i++)
			res[id[i]] = t2;
		for(int i = 0; i < n; i++){
			if(res[i] == 1){
				int tp = i, tmk = mrk[i];
				while(i >= 0 && mrk[i] == tmk) i--;
				swap(mrk[i + 1], mrk[tp]);
				i = tp;
			}
		}
		for(int i = 0; i < n; i++){
			if(i) printf(" ");
			printf("%d", res[i]);
		}
	}
	puts("");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int n, a, b;
int mrk[100010];
int id[100010], res[100010];

bool cmp(int x, int y){
	return mrk[x] < mrk[y];
}

int main(){
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	for(int i = 0; i < n; i++)
		scanf("%d", &mrk[i]);
	for(int i = 0; i < n; i++)
		id[i] = i;
	sort(id, id + n, cmp);
	if(a == b){
		for(int i = 0; i < a; i++){
			if(i) printf(" ");
			printf("1");
		}
		for(int i = a; i < n; i++){
			if(i) printf(" ");
			printf("2");
		}
	}
	else{
		int t1 = 1, t2 = 2;
		if(a < b) {swap(a, b); swap(t1, t2);}
		for(int i = 0; i < a; i++)
			res[id[i]] = t1;
		for(int i = a; i < n; i++)
			res[id[i]] = t2;
		for(int i = 0; i < n; i++){
			if(res[i] == 1){
				int tp = i, tmk = mrk[i--];
				while(i >= 0 && res[i] != 1 && mrk[i] == tmk) i--;
				swap(res[i + 1], res[tp]);
				i = tp;
			}
		}
		for(int i = 0; i < n; i++){
			if(i) printf(" ");
			printf("%d", res[i]);
		}
	}
	puts("");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int n, a, b;
int mrk[100010];
int id[100010];
int ac[7][2];

bool cmp(int x, int y){
	return mrk[x] < mrk[y];
}

int main(){
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	for(int i = 0; i < n; i++)
		scanf("%d", &mrk[i]);
	for(int i = 0; i < n; i++)
		id[i] = i;
	sort(id, id + n, cmp);
	int t1 = 1, t2 = 2;
	if(a == b){
		for(int i = 0; i < a; i++){
			if(i) printf(" ");
			printf("1");
		}
		for(int i = a; i < n; i++){
			if(i) printf(" ");
			printf("2");
		}
	}
	if(a < b) {swap(a, b); swap(t1, t2);}
	for(int i = 0; i < a; i++)
		ac[mrk[id[i]]][t1]++;
	for(int i = a; i < n; i++)
		ac[mrk[id[i]]][t2]++;
	for(int i = 0; i < n; i++){
		if(i) putchar(' ');
		if(ac[mrk[i]][1]){
			printf("1"); ac[mrk[i]][1]--;
		}
		else printf("2");
	}
	puts("");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int n, a, b;
double mrk[100010];
int id[100010], res[100010];

bool cmp(int x, int y){
	return mrk[x] < mrk[y];
}

int main(){
	scanf("%d", &n);
	scanf("%d%d", &a, &b);
	for(int i = 0; i < n; i++)
		scanf("%lf", &mrk[i]);
	for(int i = 0; i < n; i++)
		id[i] = i;
	sort(id, id + n, cmp);
	if(a == b){
		for(int i = 0; i < a; i++){
			if(i) printf(" ");
			printf("1");
		}
		for(int i = a; i < n; i++){
			if(i) printf(" ");
			printf("2");
		}
	}
	else{
		if(a < b) swap(a, b);
		for(int i = 0; i < a; i++)
			res[id[i]] = 1;
		for(int i = a; i < n; i++)
			res[id[i]] = 2;
		for(int i = 0; i < n; i++){
			if(i) printf(" ");
			printf("%d", res[i]);
		}
	}
	puts("");
	return 0;
}