#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    IOS;
    string s,t;
    cin>>s>>t;
    int n,m,i,j;
    n=s.length();
    m=t.length();
    vi v1(26),v2(26);
    for(i=0;i<n;i++) v1[s[i]-'a']++;
    for(i=0;i<m;i++) v2[t[i]-'a']++;
    // for(i=0;i<26;i++) cout<<v1[i]<<" "<<v2[i]<<endl;
    int flag=1;
    for(i=0;i<26;i++)
    {
        if(v2[i]!=0&&v1[i]==0)
        {
            flag=0;
            break;
        }
    }
    if(flag==0)
    {
        cout<<"-1";
        return 0;
    }
    vector<vector<int> > x(n,vector<int> (26,-1));
    for(i=n-2;i>=0;i--)
    {
        int num=s[i+1]-'a';
        x[i][num]=i+1;
        for(j=0;j<26;j++)
        {
            if(j==num) continue;
            x[i][j]=x[i+1][j];
        }
    }
    // for(i=0;i<n;i++)
    // {
    //     for(j=0;j<4;j++) cout<<x[i][j]<<" ";
    //     cout<<endl;
    // }
    int ans=0;
    j=-1;
    // cout<<m<<endl;
    for(i=0;i<m;i++)
    {
        if(j==-1)
        {
            ans++;
            j=0;
            if(s[j]==t[i]) ;
            else j=x[j][t[i]-'a'];
            // cout<<ans<<" "<<j<<endl;
            continue;
        }
        j=x[j][t[i]-'a'];
        if(j==-1) i--;
        // cout<<ans<<" "<<j<<endl;
    }
    cout<<ans;
}


#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    IOS;
    string s,t;
    cin>>s>>t;
    int n,m,i,j;
    n=s.length();
    m=t.length();
    vi v1(26),v2(26);
    for(i=0;i<n;i++) v1[s[i]-'a']++;
    for(i=0;i<m;i++) v2[t[i]-'a']++;
    // for(i=0;i<26;i++) cout<<v1[i]<<" "<<v2[i]<<endl;
    int flag=1;
    for(i=0;i<26;i++)
    {
        if(v2[i]!=0&&v1[i]==0)
        {
            flag=0;
            break;
        }
    }
    if(flag==0)
    {
        cout<<"-1";
        return 0;
    }
    i=0;
    j=0;
    int ans=1;
    while(j<m)
    {
        if(i==n)
        {
            ans++;
            i=0;
            continue;
        }
        if(s[i]==t[j]) j++;
        i++;
    }
    cout<<ans;
}


#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    IOS;
    string s,t;
    cin>>s>>t;
    int n,m,i,j;
    n=s.length();
    m=t.length();
    vi v1(26),v2(26);
    for(i=0;i<n;i++) v1[s[i]-'a']++;
    for(i=0;i<m;i++) v2[t[i]-'a']++;
    for(i=0;i<26;i++)
    {
        if((v1[i]==0&&v2[i]!=0)||(v1[i]!=0&&v2[i]==0))
        {
            cout<<"-1";
            return 0;
        }
    }
    i=0;
    j=0;
    int ans=1;
    while(j<m)
    {
        if(i==n)
        {
            ans++;
            i=0;
            continue;
        }
        if(s[i]==t[j]) j++;
        i++;
    }
    cout<<ans;
}


#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    IOS;
    string s,t;
    cin>>s>>t;
    int n,m,i,j;
    n=s.length();
    m=t.length();
    vi v1(26),v2(26);
    for(i=0;i<n;i++) v1[s[i]-'a']++;
    for(i=0;i<m;i++) v2[t[i]-'a']++;
    // for(i=0;i<26;i++) cout<<v1[i]<<" "<<v2[i]<<endl;
    int flag=0;
    for(i=0;i<26;i++)
    {
        if(v1[i]!=0&&v2[i]!=0)
        {
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        cout<<"-1";
        return 0;
    }
    i=0;
    j=0;
    int ans=1;
    while(j<m)
    {
        if(i==n)
        {
            ans++;
            i=0;
            continue;
        }
        if(s[i]==t[j]) j++;
        i++;
    }
    cout<<ans;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define sr(x) sort(x.begin(), x.end())
#define rv(x) reverse(x.begin(), x.end())
#define speed ios_base::sync_with_stdio(false)

using namespace std;

const int N = 1e6 + 123;
const int mod = 1e9 + 7;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const double eps = (double)(1e-9);
const double pi = 3.14159265358979323846264;
const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const pair < int, int > dir[] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};
const pair < int, int > dirr[] = {mp(-2, 1), mp(1, -2), mp(2, -1), mp(-1, 2), mp(2, 1), mp(1, 2), mp(-2, -1), mp(-1, -2)};

string s, t;
int nxt[N][27];

main() {
    cin.tie(0);
    cout.tie(0);
    cout.precision(0);
    ios_base::sync_with_stdio(0);
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for (int i = 0; i < 26; ++i) {
    	nxt[n][i] = -inf;
    }
    for (int i = n - 1; i >= 0; --i) {
    	nxt[n][s[i] - 'a'] = i;
    }
    for (int i = n - 1; i >= 0; --i) {
    	for (int j = 0; j < 26; ++j) {
    		nxt[i][j] = nxt[i + 1][j];
    	}
    	nxt[n][s[i] - 'a'] = i;
    }
    int sub = 0, cnt = 1, len = 0;
    for (int i = 0; i < m; ++i) {
    	sub = nxt[len][t[i] - 'a'];
    	if (sub == -inf) {
    		cout << -1;
    		return 0;
    	}
    	if (sub < len) {
    		cnt++;
    	}
    	len = sub + 1;
    }
    cout << cnt;
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define sr(x) sort(x.begin(), x.end())
#define rv(x) reverse(x.begin(), x.end())
#define speed ios_base::sync_with_stdio(false)

using namespace std;

const int N = 1e4 + 123;
const int mod = 1e9 + 7;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const double eps = (double)(1e-9);
const double pi = 3.14159265358979323846264;
const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const pair < int, int > dir[] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};
const pair < int, int > dirr[] = {mp(-2, 1), mp(1, -2), mp(2, -1), mp(-1, 2), mp(2, 1), mp(1, 2), mp(-2, -1), mp(-1, -2)};

string s, t;
ll nxt[N][27];

main() {
    cin.tie(0);
    cout.tie(0);
    cout.precision(0);
    ios_base::sync_with_stdio(0);
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    for (ll i = 0; i < 26; ++i) {
    	nxt[n][i] = -1;
    }
    for (ll i = n - 1; i >= 0; --i) {
    	nxt[n][s[i] - 'a'] = i;
    }
    for (ll i = n - 1; i >= 0; --i) {
    	for (ll j = 0; j < 26; ++j) {
    		nxt[i][j] = nxt[i + 1][j];
    	}
    	nxt[i][s[i] - 'a'] = i;
    }
    ll sub = 0, cnt = 1, len = 0;
    for (ll i = 0; i < m; ++i) {
    	sub = nxt[len][t[i] - 'a'];
    	if (sub == -1) {
    		cout << -1;
    		return 0;
    	}
    	if (sub < len) {
    		cnt++;
    	}
    	len = sub + 1;
    }
    cout << cnt;
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define sr(x) sort(x.begin(), x.end())
#define rv(x) reverse(x.begin(), x.end())
#define speed ios_base::sync_with_stdio(false)

using namespace std;

const int N = 1e4 + 123;
const int mod = 1e9 + 7;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const double eps = (double)(1e-9);
const double pi = 3.14159265358979323846264;
const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const pair < int, int > dir[] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};
const pair < int, int > dirr[] = {mp(-2, 1), mp(1, -2), mp(2, -1), mp(-1, 2), mp(2, 1), mp(1, 2), mp(-2, -1), mp(-1, -2)};

string s, t;
int nxt[N][27];

main() {
    cin.tie(0);
    cout.tie(0);
    cout.precision(0);
    ios_base::sync_with_stdio(0);
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for (int i = 0; i < 26; ++i) {
    	nxt[n][i] = -inf;
    }
    for (int i = n - 1; i >= 0; --i) {
    	nxt[n][s[i] - 'a'] = i;
    }
    for (int i = n - 1; i >= 0; --i) {
    	for (int j = 0; j < 26; ++j) {
    		nxt[i][j] = nxt[i + 1][j];
    	}
    	nxt[n][s[i] - 'a'] = i;
    }
    int sub = 0, cnt = 1, len = 0;
    for (int i = 0; i < m; ++i) {
    	sub = nxt[len][t[i] - 'a'];
    	if (sub == -inf) {
    		cout << -1;
    		return 0;
    	}
    	if (sub < len) {
    		cnt++;
    	}
    	len = sub + 1;
    }
    cout << cnt;
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}


/*---> praveenojha33 <---> 06 September 2019 <--- > 02:29:44 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;
vi adj[26];
int32_t main(){__
	string s1,s2;
	cin>>s1>>s2;
	int n=sz(s1);
	int m=sz(s2);
	for(int i=0;i<n;i++){
		adj[s1[i]-'a'].push_back(i);
	}
	int cur=-1,ans=1;
	for(int i=0;i<m;i++){
		int cc=s2[i]-'a';
		if(!sz(adj[cc])){
			return cout<<-1<<"\n",0;
		}
		int ind=0;
		while(ind<sz(adj[cc]) && adj[cc][ind]<=cur){
			ind++;
		}
		if(ind==sz(adj[cc])){
			cur=-1;
			ind=0;
			while(ind<sz(adj[cc]) && adj[cc][ind]<=cur){
			ind++;
			}
			ans++;
		}
		cur=adj[cc][ind];
	}
	cout<<ans<<"\n";
return 0;
}


/*---> praveenojha33 <---> 06 September 2019 <--- > 02:29:44 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;
vi adj[26];
int32_t main(){__
	string s1,s2;
	cin>>s1>>s2;
	int n=sz(s1);
	int m=sz(s2);
	for(int i=0;i<n;i++){
		adj[s1[i]-'a'].push_back(i);
	}
	int cur=-1,ans=1;
	for(int i=0;i<m;i++){
		int cc=s2[i]-'a';
		if(!sz(adj[cc])){
			return cout<<-1<<"\n",0;
		}
		int ind=upper_bound(all(adj[cc]),cur)-adj[cc].begin();
		if(ind==sz(adj[cc])){
			cur=-1;
			ind=upper_bound(all(adj[cc]),cur)-adj[cc].begin();
			ans++;
		}
		cur=ind;
	}
	cout<<ans<<"\n";
return 0;
}


/*---> praveenojha33 <---> 06 September 2019 <--- > 02:29:44 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;
vi adj[26];
int32_t main(){__
	string s1,s2;
	cin>>s1>>s2;
	int n=sz(s1);
	int m=sz(s2);
	for(int i=0;i<n;i++){
		adj[s1[i]-'a'].push_back(i);
	}
	int cur=-1,ans=1;
	for(int i=0;i<m;i++){
		int cc=s2[i]-'a';
		if(!sz(adj[cc])){
			return cout<<-1<<"\n",0;
		}
		int ind=upper_bound(all(adj[cc]),cur)-adj[cc].begin();
		if(ind==sz(adj[cc])){
			cur=-1;
			ind=upper_bound(all(adj[cc]),cur)-adj[cc].begin();
			ans++;
		}
		cur=adj[cc][ind];
	}
	cout<<ans<<"\n";
return 0;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
template <typename A, typename B> ostream& operator<<(ostream& os, pair<A,B> p) { return os << '{' << p.first << ", " << p.second << '}'; }
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;

vi pos[26];
bool mark[26];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  string a; cin >> a;
  string b; cin >> b;
  int n = sz(a);

  fo1(i, n) {
    mark[a[i]-'a'] = true;
    pos[a[i]-'a'].emplace_back(i);
  }

  fo1(i, 26) {
    if (!mark[i]) continue;
    pos[i].emplace_back(pos[i][0] + n);
  }

  int p = 1;
  int i = 0;
  for (const auto chr : b) {
    int c = chr-'a';
    if (pos[c].empty()) {
      cout << -1 << endl;
      return 0;
    }

    int j = *lower_bound(all(pos[c]), i);
    if (j >= n) {
      p++;
      i = j-n;
    } else if (j < i) {
      p++;
      i = j;
    } else {
      i = j;
    }
  }

  cout << p << endl;
  return 0;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
template <typename A, typename B> ostream& operator<<(ostream& os, pair<A,B> p) { return os << '{' << p.first << ", " << p.second << '}'; }
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;

vi pos[26];
bool mark[26];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  string a; cin >> a;
  string b; cin >> b;
  int n = sz(a);

  fo1(i, n) {
    mark[a[i]-'a'] = true;
    pos[a[i]-'a'].emplace_back(i);
  }

  fo1(i, 26) {
    if (!mark[i]) continue;
    pos[i].emplace_back(pos[i][0] + n);
  }

  int p = 1;
  int i = -1;
  for (const auto chr : b) {
    int c = chr-'a';
    if (pos[c].empty()) {
      cout << -1 << endl;
      return 0;
    }

    int j = *lower_bound(all(pos[c]), i);
    if (j >= n) {
      p++;
      i = j-n;
    } else if (j <= i) {
      p++;
      i = j;
    } else {
      i = j;
    }
  }

  cout << p << endl;
  return 0;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
template <typename A, typename B> ostream& operator<<(ostream& os, pair<A,B> p) { return os << '{' << p.first << ", " << p.second << '}'; }
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;

vi pos[26];
bool mark[26];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  string a; cin >> a;
  string b; cin >> b;
  int n = sz(a);

  fo1(i, n) {
    mark[a[i]-'a'] = true;
    pos[a[i]-'a'].emplace_back(i);
  }

  fo1(i, 26) {
    if (!mark[i]) continue;
    pos[i].emplace_back(pos[i][0] + n);
  }

  int p = 1;
  int i = -1;
  for (const auto chr : b) {
    int c = chr-'a';
    if (pos[c].empty()) {
      cout << -1 << endl;
      return 0;
    }

    int j = *lower_bound(all(pos[c]), i+1);
    if (j >= n) {
      p++;
      i = j-n;
    } else if (j <= i) {
      p++;
      i = j;
    } else {
      i = j;
    }
  }

  cout << p << endl;
  return 0;
}


///In the name of ALLAH

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

int main()
{
    optimize();

    vi v[30];
    string s1, s2;

    cin >> s1 >> s2;

    for ( int i = 0; i < sz ( s1 ); i++ ) {
        v[s1[i]-'a'].PB ( i );
    }

   // for ( int i = 0; i < 26; i++ ) sort ( all ( v[i] ) );

    int last = 0, cnt = 1;
    for ( int i = 0; i < sz ( s2 ); i++ ) {
        //cerr << last << endl;
        int id = s2[i] - 'a';
        if ( sz ( v[id] ) == 0 ) return cout << "-1", 0;
        if ( last > v[id].back() ) {
            cnt++;
            last = 0;
        }

        int up = upper_bound( all ( v[id] ), last ) - v[id].begin();
        last = v[id][up];
    }

    cout << cnt;

    return 0;
}


///In the name of ALLAH

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

int main( )
{
    optimize();

    vi v[30];
    string s1, s2;

    cin >> s1 >> s2;

    for ( int i = 0; i < sz ( s1 ); i++ ) {
        v[s1[i]-'a'].PB ( i );
    }

    int last = -1, cnt = 1;
    for ( int i = 0; i < sz ( s2 ); i++ ) {
        int id = s2[i] - 'a';
        if ( sz ( v[id] ) == 0 ) return cout << "-1", 0;
        if ( last >= v[id].back() ) {
            cnt++;
            last = -1;
        }

        int up = upper_bound( all ( v[id] ), last ) - v[id].begin();

        last = v[id][up];
    }

    cout << cnt;

    return 0;
}


///In the name of ALLAH

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

int main( )
{
    optimize();

    vi v[30];
    string s1, s2;

    cin >> s1 >> s2;

    for ( int i = 0; i < sz ( s1 ); i++ ) {
        v[s1[i]-'a'].PB ( i );
    }

    int last = 0, cnt = 1;
    for ( int i = 0; i < sz ( s2 ); i++ ) {
        int id = s2[i] - 'a';
        if ( sz ( v[id] ) == 0 ) return cout << "-1", 0;
        if ( last >= v[id].back() ) {
            cnt++;
            last = -1;
        }

        int up = upper_bound( all ( v[id] ), last ) - v[id].begin();

        last = v[id][up];
    }

    cout << cnt;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>

typedef long long ll;
#define MAX 105
using namespace std;
int n,m;
int k;
#define INF 2147483647
#define MOD 1000000009
#define EPS 1e-8
#define G 9.8
#define PI acos(-1)
bool debug = false;

int main()
{
    string a,b; cin>>a>>b;
    int ans = 0;
    for(int i=0;i<b.size();) {
        m=i;
        ans++;
        for(int j=0;j<a.size();j++) {
            if (b[i]==a[j]) i++;
        }
        if (i==m) {
            puts("-1"); return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>

typedef long long ll;
#define MAX 105
using namespace std;
int n,m;
int k;
#define INF 2147483647
#define MOD 1000000009
#define EPS 1e-8
#define G 9.8
#define PI acos(-1)
bool debug = false;

int pos[10002][26];
int main()
{
    char a[10004],b[1000006];
    scanf("%s%s", a, b);
    int ans = 0, cc[26], az = (int)strlen(a), bz =(int)strlen(b);
    for(int i=0;i<26;i++) cc[i]=az;
    for(int j=az-1;j>=0;j--) {
        for(int i=0;i<26;i++) {
            pos[j][i]=cc[i];
        }
        cc[a[j]-'a'] = j;
    }
    for(int i=0;i<bz;) {
        m=i;
        ans++;
        for(int j=0;j<az&&i<bz;) {
            if (b[i]==a[j]) { i++; j++; }
            else j = pos[j][b[i]-'a'];
        }
        if (i==m) {
            puts("-1"); return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>

typedef long long ll;
#define MAX 105
using namespace std;
int n,m;
int k;
#define INF 2147483647
#define MOD 1000000009
#define EPS 1e-8
#define G 9.8
#define PI acos(-1)
bool debug = false;

int pos[10002][26];
int main()
{
    string a,b; cin>>a>>b;
    int ans = 0, cc[26];
    for(int i=0;i<26;i++) cc[i]=(int)a.size();
    for(int j=(int)a.size()-1;j>=0;j--) {
        for(int i=0;i<26;i++) {
            pos[j][i]=cc[i];
        }
        cc[a[j]-'a'] = j;
    }
    for(int i=0;i<b.size();) {
        m=i;
        ans++;
        for(int j=0;j<a.size()&&i<b.size();) {
            if (b[i]==a[j]) { i++; j++; }
            else j = pos[j][b[i]-'a'];
        }
        if (i==m) {
            puts("-1"); return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>

typedef long long ll;
#define MAX 105
using namespace std;
int n,m;
int k;
#define INF 2147483647
#define MOD 1000000009
#define EPS 1e-8
#define G 9.8
#define PI acos(-1)
bool debug = false;

int pos[10002][26];
int main()
{
    string a,b; cin>>a>>b;
    int ans = 0, cc[26];
    for(int i=0;i<26;i++) cc[i]=(int)a.size();
    for(int j=(int)a.size()-1;j>=0;j--) {
        for(int i=0;i<26;i++) {
            pos[j][i]=cc[i];
        }
        cc[a[j]-'a'] = j;
    }
    for(int i=0;i<b.size();) {
        m=i;
        ans++;
        for(int j=0;j<a.size();) {
            if (b[i]==a[j]) { i++; j++; }
            else j = pos[j][b[i]-'a'];
        }
        if (i==m) {
            puts("-1"); return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define carpe_diem ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define S second
#define F first
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define M 1000000007

int main()
{
    carpe_diem
    string s1,s2; cin>>s1>>s2;
    int n=s1.size();
    unordered_map<char, int> m1;
    for(int i=0; i<s1.size(); i++) m1[s1[i]]++;
    for(int i=0; i<s2.size(); i++)
    {
        if(m1.find(s2[i])==m1.end()) { cout<<-1; return 0; }
    }
    map<char, vector<int> >m;
    for(int i=0; i<n; i++)
    {
        m[s1[i]].pb(i);
    }
    int i=0; int j=0;
    int ans=1;
    while(j<s2.size())
    {
        char c = s2[j];
        auto low = lower_bound( m[c].begin(), m[c].end(), i);
        if(low==m[c].end())
        {
            i=m[c][0]; ans++;
        }
        else
        {
            i=low-m[c].begin();
        }
        i++; j++;
    }
    cout<<ans<<endl;
}


#include<stdio.h>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define carpe_diem ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define S second
#define F first
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define M 1000000007

int main()
{
    carpe_diem
    string s1,s2; cin>>s1>>s2;
    int n=s1.size();
    unordered_map<char, int> m1;
    for(int i=0; i<s1.size(); i++) m1[s1[i]]++;
    for(int i=0; i<s2.size(); i++)
    {
        if(m1.find(s2[i])==m1.end()) { cout<<-1; return 0; }
    }
    map<char, vector<int> >m;
    for(int i=0; i<n; i++)
    {
        m[s1[i]].pb(i);
    }
    int i=0; int j=0;
    int ans=1;
    while(j<s2.size())
    {
        char c = s2[j];
        auto low = lower_bound( m[c].begin(), m[c].end(), i);
        if(low==m[c].end())
        {
            i=m[c][0]; ans++;
        }
        else
        {
            i=*low;
        }
        // cout<<i<<endl;
        i++; j++;
    }
    cout<<ans<<endl;
}


#include<stdio.h>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define carpe_diem ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define S second
#define F first
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define M 1000000007

int main()
{
    carpe_diem
    string s1,s2; cin>>s1>>s2;
    unordered_map<char, int> m1;
    for(int i=0; i<s1.size(); i++) m1[s1[i]]++;
    for(int i=0; i<s2.size(); i++)
    {
        if(m1.find(s2[i])==m1.end()) { cout<<-1; return 0; }
    }
    int j=0; int i=0; int n=s1.size();
    while(j<s2.size())
    {
        while(s2[j]!=s1[i%n]) i++;
        j++; i++;
    }
    int ans=i/n;
    if(i%n!=0) ans++;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string w,t;
    cin>>w>>t;

    set<char> A;
    map<char,set<int> > where;
    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
        where[ w[i] ].insert(i);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;
   /* for(auto e : where)
    {
        cout<<e.x<<" : ";
        for(auto r : e.y)
            cout<<r<<" ";
        cout<<endl;
    }

    cout<<" first pos = "<<*where[ t[pos] ].begin()<<endl<<endl;
    cout<<t<<endl;*/
    int cnt = 0;
    while(pos < t.size())
    {
        ans++;
        bool ok = 0;

        for(i = *where[ t[pos] ].begin(); i < w.size();)
        {
            if(t[pos] == w[i])
            {
                //cout<<" before i = "<<i<<" cnt = "<<cnt<<"   "<<t[pos]<<endl;
                cnt++;
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }

                if(*where[ t[pos] ].rbegin() <=  i)
                {
                   // cout<<" *where[ t[pos] ].rbegin() = "<<*where[ t[pos] ].rbegin()<<" <  i = "<<i<<endl;
                    break;
                }

                auto need = where[ t[pos] ].upper_bound(i);
                if(need == where[ t[pos] ].end() )
                    break;

                int was = i;
                i = *need;
                if(i == w.size() - 1 && was == w.size() - 1)
                    break;

              //  cout<<" after i = "<<i<<endl;
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string w,t;
    cin>>w>>t;

    set<char> A;
    map<char,set<int> > where;
    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
        where[ w[i] ].insert(i);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;
    /*for(auto e : where)
    {
        cout<<e.x<<" : ";
        for(auto r : e.y)
            cout<<r<<" ";
        cout<<endl;
    }*/

   // cout<<" first pos = "<<*where[ t[pos] ].begin()<<endl<<endl;

    int cnt = 0;
    while(pos < t.size())
    {
        ans++;
        bool ok = 0;

        for(i = *where[ t[pos] ].begin(); i < w.size();)
        {
            if(t[pos] == w[i])
            {
               // cout<<" before i = "<<i<<" cnt = "<<cnt<<endl;
                cnt++;
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }

                if(*where[ t[pos] ].rbegin() <=  i)
                {
                    //cout<<" *where[ t[pos] ].rbegin() = "<<*where[ t[pos] ].rbegin()<<" <  i = "<<i<<endl;
                    break;
                }

                auto need = where[ t[pos] ].lower_bound(i);
                if(need == where[ t[pos] ].end() )
                    break;

                int was = i;
                i = *need;
                if(i == w.size() - 1 && was == w.size() - 1)
                    break;

                //cout<<" after i = "<<i<<endl;
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string w,t;
    cin>>w>>t;

    set<char> A;
    map<char,set<int> > where;
    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
        where[ w[i] ].insert(i);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;

    while(pos < t.size())
    {
        ans++;
        bool ok = 0;

        for(i = *where[ t[pos] ].begin(); i < w.size();)
        {
            if(t[pos] == w[i])
            {
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }

                if(*where[ t[pos] ].rbegin() <  i)
                {
                    break;
                }

                auto need = where[ t[pos] ].lower_bound(i);
                if(need == where[ t[pos] ].end() )
                    break;

                i = *need;
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string w,t;
    cin>>w>>t;

    set<char> A;
    map<char,set<int> > where;
    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
        where[ w[i] ].insert(i);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;
    /*for(auto e : where)
    {
        cout<<e.x<<" : ";
        for(auto r : e.y)
            cout<<r<<" ";
        cout<<endl;
    }

    cout<<" first pos = "<<*where[ t[pos] ].begin()<<endl<<endl;*/
    while(pos < t.size())
    {
        ans++;
        bool ok = 0;

        for(i = *where[ t[pos] ].begin(); i < w.size();)
        {
            if(t[pos] == w[i])
            {
               // cout<<" i = "<<i<<endl;
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }

                if(*where[ t[pos] ].rbegin() <  i)
                {
                    break;
                }

                auto need = where[ t[pos] ].lower_bound(i);
                if(need == where[ t[pos] ].end() )
                    break;

                i = *need;
                if(i == w.size() - 1)
                    break;
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

   // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

    freopen("in.txt","r",stdin);
    cout << fixed;cout.precision(10);

    string w,t;
    cin>>w>>t;

    set<char> A;
    map<char,set<int> > where;
    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
        where[ w[i] ].insert(i);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;
    /*for(auto e : where)
    {
        cout<<e.x<<" : ";
        for(auto r : e.y)
            cout<<r<<" ";
        cout<<endl;
    }

    cout<<" first pos = "<<*where[ t[pos] ].begin()<<endl<<endl;*/
    while(pos < t.size())
    {
        ans++;
        bool ok = 0;

        for(i = *where[ t[pos] ].begin(); i < w.size();)
        {
            if(t[pos] == w[i])
            {
               // cout<<" i = "<<i<<endl;
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }

                if(*where[ t[pos] ].rbegin() <  i)
                {
                    break;
                }

                auto need = where[ t[pos] ].lower_bound(i);
                if(need == where[ t[pos] ].end() )
                    break;

                i = *need;
                if(i == w.size() - 1)
                    break;
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a.size())
#define Pi acos(-1.)
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAXN = 2e5+5;
const int MAXM = 1e4+500;
const int N = 500 + 5;
const double EPS = 1e-9;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
ll i,j,d;
ll n,k,m;

ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    set<char> A;
    string w,t;
    cin>>w>>t;

    for(i=0;i<w.size();i++)
    {
        A.insert(w[i]);
    }

    for(i=0;i<t.size();i++)
    {
        if(A.count(t[i]) == 0)
        {
            cout<<-1;
            return 0;
        }
    }

    int ans = 0;
    int pos = 0;

    while(pos < t.size())
    {
        ans++;
        bool ok = 0;
        for(i=0;i<w.size();i++)
        {
            if(t[pos] == w[i])
            {
                pos++;
                if(pos == t.size())
                {
                    ok = 1;
                    break;
                }
            }
        }

        if(ok)
            break;
    }

    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long int
#define f(i,n) for(int i=0;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}

int main() {
    cin>>s>>z;
    ll j=-1,c=0;
    n=s.size();
    for(ll i=0;i<z.size();i++)
    {
        c=0;
        j++;
        while(s[j%n]!=z[i])
        {
            j++;
            c++;
            if(c>n)
            {
                cout<<-1;return 0;
            }
        }
       // cout<<s[j%n]<<z[i]<<ln;
    }

    cout<<j/n+1;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long int
#define f(i,n) for(int i=0;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}

int main() {
    cin>>s>>z;
    ll j=-1,c=1;
    n=s.size();
ll a[n][26]={0};

    for(int i=0;i<26;i++)a[n-1][i]=-1;
    a[n-1][s[n-1]-'a']=n-1;
    for(int i=n-2;i>=0;i--)
    {
        for(int j=0;j<26;j++)
        {
            a[i][j]=a[i+1][j];
        }
        a[i][s[i]-'a']=i;
    }
    for(ll i=0;i<z.size();i++)
    {
      j++;
      if(j==n)
      {
          c++;
          j=0;
      }
      if(a[j][z[i]-'a']!=-1)j=a[j][z[i]-'a'];
      else if(a[0][z[i]-'a']!=-1)
      {
         j=a[0][z[i]-'a'];
          c++;
      }
      else
      {
          cout<<-1;return 0;
      }
    }

    cout<<c;
}


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

string headline, word;
int pos[1000001];

int main() {
    cin >> headline >> word;
    for (int i = 0; i < word.size(); i++) {
        pos[i] = headline.size();
        for (int j = 0; j < headline.size(); j++) {
            if (headline[j] == word[i]) {
                pos[i] = j;
            }
        }
    }
    int i = 0;
    int j = 0;
    int result = 1;
    while (i < word.size()) {
        if (pos[i] == headline.size()){
            result = -1;
            break;
        }
        if (pos[i] < j)  result++;
        j = pos[i];
        i++;
    }
    cout << result;
}


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

string headline, word;
int pos[27][10001];

int main() {
    cin >> headline >> word;
    for (int i = 0; i < 27; i++) {
        int next = headline.size();
        for (int j = headline.size() - 1; j >= 0; j--) {
            if (headline[j] == char(i + 'a')) {
                next = j;
            }
            pos[i][j] = next;
        }
    }
    int j = 0;
    int result = 1;
    for (int i = 0; i < word.size(); i++) {
        if (j == headline.size()) {
            result++;
            j = 0;
        }
        if (pos[word[i] - 'a'][j] == headline.size()){
            result++;
            j = pos[word[i] - 'a'][0] + 1;
            if (j == headline.size() + 1) {
                result = -1;
                break;
            }
        } else {
            j = pos[word[i] - 'a'][j] + 1;
        }
    }
    cout << result;
}


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

string headline, word;
int pos[1000001];

int main() {
    cin >> headline >> word;
    for (int i = 0; i < word.size(); i++) {
        pos[i] = headline.size();
        for (int j = 0; j < headline.size(); j++) {
            if (headline[j] == word[i]) {
                pos[i] = j;
            }
        }
    }
    int i = 0;
    int j = 0;
    int result = 1;
    while (i < word.size()) {
        if (pos[i] == headline.size()){
            result = -1;
            break;
        }
        if (pos[i] <= j)  result++;
        j = pos[i];
        i++;
    }
    cout << result;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=LLONG_MAX,N=1e7+5,INF=1e18;

void solve()
{
    string s1,s2;
    cin >> s1 >> s2;
    ll res=0,p=-1;
    vll c(26,0),cs2(26,0),cs1(26,0);
    vector<vll> a(26);

    f(i,0,sz(s1))
    {
        a[s1[i]-'a'].pb(i);
        cs1[s1[i]-'a']++;
    }
    f(i,0,26)
    {
        a[i].pb(-1);
    }

    f(i,0,sz(s2))
    {
        cs2[s2[i]-'a']++;
    }

    f(i,0,26)
    {
        if(cs2[i]>0 && cs1[i]==0)
        {
            cout << -1 << endl;
            return;
        }
    }

    f(i,0,sz(s2))
    {
        while( a[s2[i]-'a'][ c[s2[i]-'a'] ]<p && a[s2[i]-'a'][ c[s2[i]-'a'] ] != -1)
        {
            c[s2[i]-'a']++;
        }

        if(a[s2[i]-'a'][ c[s2[i]-'a'] ]==sz(s1)-1 )
        {
            res++;
            f(j,0,26)
                c[j]=0;
            p=-1;
        }
        else if(a[s2[i]-'a'][ c[s2[i]-'a'] ]==-1)
        {
            res++;
            f(j,0,26)
                c[j]=0;
            c[s2[i]-'a']++;
            p=a[s2[i]-'a'][ c[s2[i]-'a'] -1];
        }
        else
        {
            p=a[s2[i]-'a'][ c[s2[i]-'a'] ];
            c[s2[i]-'a']++;
        }

        cout << i << " " << res << endl;
    }

    f(i,0,26)
    {
        if(c[i]>0)
        {
            res++;
            break;
        }
    }

    cout << res << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=LLONG_MAX,N=1e7+5,INF=1e18;

void solve()
{
    string s1,s2;
    cin >> s1 >> s2;
    ll res=0;
    vll c(26,0),cs2(26,0),cs1(26,0);
    vector<vll> a(26);

    f(i,0,sz(s1))
    {
        a[s1[i]-'a'].pb(i);
        cs1[s1[i]-'a']++;
    }
    f(i,0,26)
    {
        a[i].pb(-1);
    }

    f(i,0,sz(s2))
    {
        cs2[s2[i]-'a']++;
    }

    f(i,0,26)
    {
        if(cs2[i]>0 && cs1[i]==0)
        {
            cout << -1 << endl;
            return;
        }
    }

    f(i,0,sz(s2))
    {
        if( (a[s2[i]-'a'][ c[s2[i]-'a'] ]==sz(s1)-1))
        {
            res++;
            f(j,0,26)
                c[j]=0;
        }
        else if(a[s2[i]-'a'][ c[s2[i]-'a'] ]==-1)
        {
            res++;
            f(j,0,26)
                c[j]=0;
            c[s2[i]-'a']++;
        }
        else
        {
            c[s2[i]-'a']++;
        }
        // cout << i << " " << res << endl;
    }

    f(i,0,26)
    {
        if(c[i]>0)
        {
            res++;
            break;
        }
    }

    cout << res << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=LLONG_MAX,N=1e7+5,INF=1e18;

void solve()
{
    string s1,s2;
    cin >> s1 >> s2;
    ll res=0;
    vll c(26,0),cs2(26,0),cs1(26,0);
    vector<vll> a(26);

    f(i,0,sz(s1))
    {
        a[s1[i]-'a'].pb(i);
        cs1[s1[i]-'a']++;
    }

    f(i,0,sz(s2))
    {
        cs2[s2[i]-'a']++;
    }

    f(i,0,26)
    {
        if(cs2[i]>0 && cs1[i]==0)
        {
            cout << -1 << endl;
            return;
        }
    }

    f(i,0,sz(s2))
    {
        if( sz(a[s2[i]-'a']) < c[s2[i]-'a'] || a [s2[i]-'a'] [ c[s2[i]-'a'] ]==sz(s1)-1)
        {
            res++;
            f(j,0,26)
                c[j]=0;
        }
        else
        {
            c[s2[i]-'a']++;
        }
    }

    f(i,0,26)
    {
        if(c[i]>0)
        {
            res++;
            break;
        }
    }

    cout << res << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=LLONG_MAX,N=1e7+5,INF=1e18;

void solve()
{
    string s1,s2;
    cin >> s1 >> s2;
    ll res=0,p=-1;
    vll c(26,0),cs2(26,0),cs1(26,0);
    vector<vll> a(26);

    f(i,0,sz(s1))
    {
        a[s1[i]-'a'].pb(i);
        cs1[s1[i]-'a']++;
    }
    f(i,0,26)
    {
        a[i].pb(-1);
    }

    f(i,0,sz(s2))
    {
        cs2[s2[i]-'a']++;
    }

    f(i,0,26)
    {
        if(cs2[i]>0 && cs1[i]==0)
        {
            cout << -1 << endl;
            return;
        }
    }

    f(i,0,sz(s2))
    {
        while( a[s2[i]-'a'][ c[s2[i]-'a'] ]<p && a[s2[i]-'a'][ c[s2[i]-'a'] ] != -1)
        {
            c[s2[i]-'a']++;
        }

        if(a[s2[i]-'a'][ c[s2[i]-'a'] ]==sz(s1)-1 )
        {
            res++;
            f(j,0,26)
                c[j]=0;
            p=-1;
        }
        else if(a[s2[i]-'a'][ c[s2[i]-'a'] ]==-1)
        {
            res++;
            f(j,0,26)
                c[j]=0;
            c[s2[i]-'a']++;
            p=a[s2[i]-'a'][ c[s2[i]-'a'] -1];
        }
        else
        {
            p=a[s2[i]-'a'][ c[s2[i]-'a'] ];
            c[s2[i]-'a']++;
        }

        // cout << i << " " << res << endl;
    }

    f(i,0,26)
    {
        if(c[i]>0)
        {
            res++;
            break;
        }
    }

    cout << res << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}


#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=LLONG_MAX,N=1e7+5,INF=1e18;

void solve()
{
    string s1,s2;
    cin >> s1 >> s2;
    ll res=0;
    vll c(26,0),cs2(26,0),cs1(26,0);
    vector<vll> a(26);

    f(i,0,sz(s1))
    {
        a[s1[i]-'a'].pb(i);
        cs1[s1[i]-'a']++;
    }

    f(i,0,sz(s2))
    {
        cs2[s2[i]-'a']++;
    }

    f(i,0,26)
    {
        if(cs2[i]>0 && cs1[i]==0)
        {
            cout << -1 << endl;
            return;
        }
    }

    f(i,0,sz(s2))
    {
        if( (sz(a[s2[i]-'a']) < c[s2[i]-'a']) || (a [s2[i]-'a'] [ c[s2[i]-'a'] ]==sz(s1)-1))
        {
            res++;
            f(j,0,26)
                c[j]=0;
        }
        else
        {
            c[s2[i]-'a']++;
        }
    }

    f(i,0,26)
    {
        if(c[i]>0)
        {
            res++;
            break;
        }
    }

    cout << res << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}


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

vector<int> adj[28];

int main() {
	string s, str;
	cin >> s >> str;
	int n = s.size();
	for(int i = 0; i < n; ++i)
		adj[s[i] - 'a'].push_back(i);
	int answer = 1, last = -1;
	n = str.size();
	bool ok = true;
	vector<int> :: iterator it;
	for(int i = 0; i < n; ++i) {
		int cur = str[i] - 'a';
		it = lower_bound(adj[cur].begin(), adj[cur].end(), last);
		if(it == adj[cur].end()) {
			if(!ok)
				return cout << -1, 0;
			last = -1;
			++answer;
			--i;
			ok = false;
			continue;
		}
		last = *it;
		ok = true;
	}
	cout << answer;
}


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

vector<int> adj[28];

int main() {
	string s, str;
	cin >> s >> str;
	int n = s.size();
	for(int i = 0; i < n; ++i)
		adj[s[i] - 'a'].push_back(i);
	int answer = 1, last = -1;
	n = str.size();
	bool ok = true;
	vector<int> :: iterator it;
	for(int i = 0; i < n; ++i) {
		int cur = str[i] - 'a';
		it = upper_bound(adj[cur].begin(), adj[cur].end(), last);
		if(it == adj[cur].end()) {
			if(!ok)
				return cout << -1, 0;
			last = -1;
			++answer;
			--i;
			ok = false;
			continue;
		}
		last = *it;
		ok = true;
	}
	cout << answer;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
	map<char,vector<int> >M;
	string s1,s2;
	int i;
	cin>>s1>>s2;
	for(i=0;i<s1.length();i++){
		M[s1[i]].push_back(i+1);
	}
	/*for(auto it=M.begin();it!=M.end();it++){
		cout<<it->first<<"->";
		for(auto il=it->second.begin();il!=it->second.end();il++){
			cout<<*il<<' ';
		}

		cout<<"\n"<<*it->second.begin()<<"\n\n";
	}*/
	int c=1,prev=0;
	for(i=0;i<s2.length();i++){
		auto it=M.find(s2[i]);
		if(it==M.end()){
			break;
		}
		else{
			bool x=false;
			for(auto il=it->second.begin();il!=it->second.end();il++){
				if(*il>prev){
					prev=*il;
					x=true;
					break;
				}
			}
			if(!x){
				prev=*it->second.begin();
				c++;
			}
		}
	}
	if(i==s2.length()){
		cout<<c<<"\n";
	}
	else{
		cout<<"-1\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
main()
{
	map<char,vector<int> >M;
	string s1,s2;
	int i;
	cin>>s1>>s2;
	for(i=0;i<s1.length();i++){
		M[s1[i]].push_back(i+1);
	}
	/*auto ip=M.begin();
	cout<<(*ip).first<<"->"<<(*ip).second[0]<<'\n';
	for( const auto& pair : M )
        {
            cout << "key: " << pair.first << "  value: [  " ;
            for( std::size_t i = 0 ; i < pair.second.size() ; ++i )  std::cout << pair.second[i] << "  " ;
            std::cout << "]\n" ;
        }
    int n;
    cin>>n; char c;
    while(n--){
    	cin>>c;
    	bool x=false;
	for(auto& it: M){
		if(it.first==c){
		cout<<it.first<<"-> Find:";
		int p,max=0;cin>>p;
		size_t mid,l=0,h=it.second.size()-1;
		if(p>=it.second[0])
		while(l<=h){
			mid=(l+h)/2;
			if(it.second[mid]>p){
				max=it.second[mid];
				h=mid-1;
			}
			else{
				l=mid+1;
			}
		}
		else max=it.second[0];
		cout<<max<<"\n"; x=true;
		break;
}}
	if(!x)cout<<"-1\n";
		//cout<<"\n"<<*it->second.begin()<<"\n\n";
	}*/
	int c=1,prev=0;
	for(i=0;i<s2.length();i++){
		auto it=M.find(s2[i]);
		if(it==M.end()){
			break;
		}
		else{
			bool x=false;
			/*for(auto il=it->second.begin();il!=it->second.end();il++){
				if(*il>prev){
					prev=*il;
					x=true;
					break;
				}
			}*/
			size_t mid,l=0,h=(*it).second.size()-1;
			int max=0;
			if(prev>=(*it).second[0]){
				while(l<=h){
					mid=(l+h)/2;
					if((*it).second[mid]>prev){
					max=(*it).second[mid];
					h=mid-1;
				}
				else{
					l=mid+1;
				}
			}
			}
			else max=(*it).second[0];

			if(max==0){
				prev=(*it).second[0];
				c++;
			}
			else{
				prev=max;
			}
		}
	}
	if(i==s2.length()){
		cout<<c<<"\n";
	}
	else{
		cout<<"-1\n";
	}
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 1000041
using namespace std;

int mp[mxn],inarray[mxn],start[mxn],end1[mxn];
int main()
{
    FLASH
    ll n;
    cin >> n;
    ll a[n],b[n];
    memset(start,-1,sizeof(start));
    memset(end1,-1,sizeof(end1));
    vector<int> remain;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        inarray[a[i]]++;
        if(start[a[i]] == -1)
            start[a[i]] = i;
        end1[a[i]] = i;
    }
    ll i = 0,k = 0,j = 0;

    while(i < n)
    {
        j = i;
        j = end1[a[i]];
        int temp = -1;
        if(a[i] == a[n - 1])
        {
            k = remain[0];
            while(inarray[k] >= 1 || mp[k] == 1)
                k++;
            if(k == a[i])
                k++;
            for(;i < n; i++)
                b[i] = k;
            break;
        }
        if(temp == -1)
            temp = k;
        for(;i <= j; i++)
        {
            bool ok = true;
            int k2 = 0;
            for(int r = 0; r < remain.size(); r++)
            {
                int val = remain[r];
                if(mp[val] == 1 || inarray[val] >= 1 || val == a[i]);
                else{
                    k2 = val;
                    remain.erase(remain.begin() + r);
                    ok = false;
                    break;
                }
            }
            while( (mp[k] == 1 || inarray[k] >= 1 || k == a[i]) && ok )
            {
                if(mp[k] == 0)
                    remain.pb(k);
                k++;
            }
            if(ok){
                b[i] = k;
                mp[k] = 1;
            }
            else{
                b[i] = k2;
                mp[k2] = 1;
            }
            inarray[a[i]]--;
        }
       // if(remain.empty() == 0)
        //k = remain[0];
        //remain.clear();
    }
    memset(mp,0,sizeof(mp));
    k = 0;
    for(int i = 0; i < n; i++)
    {
        mp[b[i]] = 1;
        while(mp[k] == 1){
            k++;
        }
        if(a[i] != k){
            cout << i << '\n';
            return 0;
        }
    }
    for(int i = 0; i < n; i++)
        cout << b[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    int t = 1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll a[n],b[n];

        map<ll,ll> mp;
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int i = 0,k = 0,j = 0;

        while(i < n)
        {
            j = i;
            while(j < n - 1 && a[j] == a[j + 1])
            {
                j++;
            }
            while(mp[k] == 1)
                k++;
            if(a[i] == a[n - 1])
            {
                    if(k == a[i])
                        k++;
                    for(;i < n; i++)
                        b[i] = k;
                    break;
            }
            int ind = j + 1,temp = k;
            for(;i <= j; i++)
            {
                if(k < a[ind] && mp[k] == 1)
                {
                    k++;
                }
                if(k == a[i])
                {
                    k++;
                }
                while(k == a[ind]){
                    if(ind >= n - 1);
                    else
                        ind++;
                    k++;
                    if(i >= n - 1)
                        break;
                }
                b[i] = k;
                mp[k] = 1;
            }
            k = temp ;
        }
        mp.clear();
        k = 0;
        for(int i = 0; i < n; i++)
        {
            mp[b[i]] = 1;
            while(mp[k] == 1){
                k++;
            }
            if(a[i] != k){
                cout << -1;
                return 0;
            }
        }
        for(int i = 0; i < n; i++)
            cout << b[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    int t = 1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll a[n],b[n];

        map<ll,ll> mp;
        for(int i = 0; i < n; i++)
            cin >> a[i];
        int i = 0,k = 0,j = 0;

        while(i < n)
        {
            j = i;
            while(j < n - 1 && a[j] == a[j + 1])
            {
                j++;
            }
            if(a[i] == a[n - 1])
            {
                    while(mp[k] == 1)
                        k++;
                    if(k == a[i])
                        k++;
                    for(;i < n; i++)
                        b[i] = k;
            }
            int ind = j + 1,temp = k;
            for(;i <= j; i++)
            {
                if(k < a[ind] && mp[k] == 1)
                {
                    k++;
                }
                if(k == a[ind])
                {
                    if(ind < n - 1)
                        ind++;
                    k++;
                }
                if(k == a[i])
                {
                    temp = k;
                    k++;
                }
                b[i] = k;
                mp[k] = 1;
            }
            k = temp ;
        }
        mp.clear();
        k = 0;
        for(int i = 0; i < n; i++)
        {
            mp[b[i]] = 1;
            while(mp[k] == 1){
                k++;
            }
            if(a[i] != k){
                cout << -1;
                return 0;
            }
        }
        for(int i = 0; i < n; i++)
            cout << b[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 1000041
using namespace std;

int mp[mxn],inarray[mxn];
int main()
{
    FLASH
    int n;
    cin >> n;
    ll a[n],b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        inarray[a[i]]++;
    }
    ll i = 0,k = 0,j = 0;

    while(i < n)
    {
        j = i;
        while(j < n - 1 && a[j] == a[j + 1])
        {
            j++;
        }
        int temp = -1;
        while(mp[k] == 1 ){
            k++;
        }
        if(inarray[k] != 0)
        {
            if(temp == -1)
                temp = k;
            while(inarray[k] >= 1 || mp[k] == 1)
                k++;
        }

        if(a[i] == a[n - 1])
        {
            if(k == a[i])
                k++;
            for(;i < n; i++)
                b[i] = k;
            break;
        }

        ll ind = j + 1;
        if(temp == -1)
            temp = k;
        for(;i <= j; i++)
        {
            while(mp[k] == 1 || inarray[k] >= 1 || k == a[i] || k == a[ind])
            {
                k++;
                while(k == a[ind])
                {
                    while(ind < n - 1 && k == a[ind])
                        ind++;
                    k++;
                    if(ind >= n - 1)
                        break;
                    else
                        ind++;
                }
            }
            b[i] = k;
            inarray[a[i]]--;
            mp[k] = 1;
        }
        k = temp ;
    }
    memset(mp,0,sizeof(mp));
    k = 0;
    for(int i = 0; i < n; i++)
    {
        mp[b[i]] = 1;
        while(mp[k] == 1){
            k++;
        }
        if(a[i] != k){
            cout << -1 << '\n';
            return 0;
        }
    }
    for(int i = 0; i < n; i++)
        cout << b[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    int t = 1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll a[n],b[n];

        map<ll,ll> mp,inarray;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            inarray[a[i]]++;
        }
        ll i = 0,k = 0,j = 0;

        while(i < n)
        {
            j = i;
            while(j < n - 1 && a[j] == a[j + 1])
            {
                j++;
            }
            int temp = -1;
            while(mp[k] == 1 ){
                k++;
            }
            if(inarray[k] != 0)
            {
                if(temp == -1)
                    temp = k;
                while(inarray[k] >= 1 || mp[k] == 1)
                    k++;
            }
            if(a[i] == a[n - 1])
            {
                    if(k == a[i])
                        k++;
                    for(;i < n; i++)
                        b[i] = k;
                    break;
            }
            ll ind = j + 1;
            if(temp == -1)
                temp = k;
            for(;i <= j; i++)
            {
                if(mp[k] == 1)
                {
                    k++;
                }
                if(k == a[i])
                {
                    k++;
                }
                while(k == a[ind]){
                    while(ind < n - 1 && k == a[ind])
                        ind++;
                    k++;
                    if(ind >= n - 1)
                        break;
                    else
                        ind++;
                }
                while(mp[k] == 1 || inarray[k] >= 1 || k == a[i]){
                    k++;
                    if(k == a[i])
                    {
                        k++;
                    }
                    while(k == a[ind]){
                        while(ind < n - 1 && k == a[ind])
                            ind++;
                        k++;
                        if(ind >= n - 1)
                            break;
                        else
                            ind++;
                    }
                }
                b[i] = k;
                inarray[a[i]]--;
                mp[k] = 1;
            }
            k = temp ;
        }
        mp.clear();
        k = 0;
        for(int i = 0; i < n; i++)
        {
            mp[b[i]] = 1;
            while(mp[k] == 1){
                k++;
            }
            if(a[i] != k){
                cout << -1 << '\n';
                return 0;
            }
        }
        for(int i = 0; i < n; i++)
            cout << b[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    int t = 1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll a[n],b[n];

        map<ll,ll> mp;
        for(int i = 0; i < n; i++)
            cin >> a[i];
        ll i = 0,k = 0,j = 0;

        while(i < n)
        {
            j = i;
            while(j < n - 1 && a[j] == a[j + 1])
            {
                j++;
            }
            while(mp[k] == 1)
                k++;
            if(a[i] == a[n - 1])
            {
                    if(k == a[i])
                        k++;
                    for(;i < n; i++)
                        b[i] = k;
                    break;
            }
            ll ind = j + 1,temp = k;
            for(;i <= j; i++)
            {
                if(mp[k] == 1)
                {
                    k++;
                }
                if(k == a[i])
                {
                    k++;
                }
                while(k == a[ind]){
                    k++;
                    if(i >= n - 1)
                        break;
                    else
                        ind++;
                }
                while(mp[k] == 1){
                    k++;
                    if(k == a[i])
                    {
                        k++;
                    }
                    while(k == a[ind]){
                        k++;
                        if(i >= n - 1)
                            break;
                        else
                            ind++;
                    }
                }
                b[i] = k;
                mp[k] = 1;
            }
            k = temp ;
        }
        mp.clear();
        k = 0;
        for(int i = 0; i < n; i++)
        {
            mp[b[i]] = 1;
            while(mp[k] == 1){
                k++;
            }
            if(a[i] != k){
                cout << -1;
                return 0;
            }
        }
        for(int i = 0; i < n; i++)
            cout << b[i] << " ";
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
            h[b[i]]=true;
        }
        // h[b[1]]=false;
        if(a[1]==0)
        for(int i=0; i<=n; i++){
            if(h[i]!=true){
                b[1] = i+1;
                break;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);

    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    vector<int> b(n+1);

    for(int i=n;i>0;i--){
        if(a[i]!=a[i-1]){
            b[i] = a[i-1];
        }else{
            b[i] = a[i]+1;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+a[n];
            }
        }
        b[1] = a[n]-1;
        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        // if(a[i]>n)pos=false;
    }
    // if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1, -1);
        for(int i=n; i>0; i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
                h[b[i]]=true;
            }
        }
        int m = 0;
        for(int i=1; i<=n; i++){
            if(b[i]==-1){
                while(h[m]==true)m++;
                b[i]=m;
                h[m]=true;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    // }
    // else{
        // cout<<-1<<endl;
    // }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
        }
        if(a[1]==0){
            if(a[n]<n)
            b[1] = a[n]+1;
            else
            b[1] = a[n]-1;
        }
        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1, -1);
        for(int i=n; i>0; i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
                h[b[i]]=true;
            }
        }
        int m = 0;
        h[a[n]]=true;
        for(int i=1; i<=n; i++){
            if(b[i]==-1){
                while(h[m]==true)m++;
                b[i]=m;
                h[m]=true;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
        }
        if(a[1]==0)
        b[1] = a[n]-1;
        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1, -1);
        for(int i=n; i>0; i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
                h[b[i]]=true;
            }
        }
        int m = 0;
        for(int i=1; i<=n; i++){
            if(b[i]==-1){
                while(h[m]==true)m++;
                b[i]=m;
                h[m]=true;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1);
        for(int i=n; i>0; i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
            h[b[i]]=true;
        }
        if(a[1]==0 && b[1]!=1)
        for(int i=0; i<=n; i++){
            if(h[i]!=true){
                b[1] = i+1;
                break;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        unordered_map<int, bool> h;
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
            h[b[i]]=true;
        }
        h[b[1]]=false;
        if(a[1]==0)
        for(int i=0; i<=n; i++){
            if(h[i]!=true){
                b[1] = i;
                break;
            }
        }

        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1,0);
    int mx = n;
    bool pos = true;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>n)pos=false;
    }
    if(pos){
        vector<int> b(n+1);
        for(int i=n;i>0;i--){
            if(a[i]!=a[i-1]){
                b[i] = a[i-1];
            }else{
                b[i] = a[i]+1;
            }
        }
        if(a[1]==0){
            if(a[n]<n)
            b[1] = n;
            else
            b[1] = a[n]-1;
        }
        for(int i=1;i<=n;i++){
            cout<<b[i]<<" ";
        }
        cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        vector <ll> pos;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()>0);
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
                if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) cnt++;
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                    cnt=0;
                    continue;
                }
                for(int j=i-1;j>=i-cnt;j--) {
                    b[j]=last;
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
                if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }
                cnt=0;
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) cnt++;
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                    continue;
                }
                for(int j=i-1;j>=i-cnt;j--) {
                    b[j]=last;
                    s.insert(last);
                    if(last==a[i]-1) break;
                    last++;
                }
                if(last!=a[i]-1) {
                    cout << "-1";
                    return 0;
                }
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}