#include <iostream>
using namespace std;
 
string shuffle (string &s1, string &s2) {
	string s;
	for (int i = 0; i < s1.length(); i++) {
		s += s2[i];
		s += s1[i];
	}
	s1 = s.substr(0, s1.length());
	s2 = s.substr(s2.length(), s2.length());
	return s;
} 
 
int main() {
	string s1, s2, s;
	int n;
	while (cin >> n && n) {
		cin >> s1 >> s2 >> s;
		string s12 = s1; s12 += s2;
		string fixS = s12;
		bool flag = true;
		int nofs = 0;			// number of steps
		do {
			nofs++;
			s12 = shuffle(s1, s2);
			if (s == s12)
				flag = false;
		} while (s12 != fixS && flag && nofs <= 50);
		cout << (flag ? -1 : nofs) << endl;
	}
	return 0;
}