#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class LittleElephantAndString { public:
	int getNumber(string A, string B)
	{
		string AA = A, BB = B;
		sort(AA.begin(), AA.end());
		sort(BB.begin(), BB.end());
		if(AA != BB)
			return -1;
		for(int n=0; n<B.size(); ++n)
			if(sup_sub(A, B.substr(n)))
				return n;
		assert(false);
	}

	bool sup_sub(const string& A, const string& B)
	{
		for(int a=0, b=0; b<B.size(); ++a,++b)
		{
			while(a<A.size() && A[a]!=B[b])
				++a;
			if(a == A.size())
				return false;
		}
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, LittleElephantAndString().getNumber(A, B));}
int main(){

CASE(0)
	string A = "ABC"; 
	string B = "CBA"; 
	int _ = 2; 
END
CASE(1)
	string A = "A"; 
	string B = "B"; 
	int _ = -1; 
END
CASE(2)
	string A = "AAABBB"; 
	string B = "BBBAAA"; 
	int _ = 3; 
END
CASE(3)
	string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	string B = "ZYXWVUTSRQPONMLKJIHGFEDCBA"; 
	int _ = 25; 
END
CASE(4)
	string A = "A"; 
	string B = "A"; 
	int _ = 0; 
END
CASE(5)
	string A = "DCABA"; 
	string B = "DACBA"; 
	int _ = 2; 
END
/*
CASE(6)
	string A = ; 
	string B = ; 
	int _ = ; 
END
CASE(7)
	string A = ; 
	string B = ; 
	int _ = ; 
END
*/
}
// END CUT HERE
