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

int main() {
	int n;
	while( cin >> n && n){
		int count = 0;
		char *first = new char[n+1];
		char *second = new char[n+1];
		char *third = new char[2 * n+1];
		char *result = new char[2 * n+1];
		cin >> first;
		cin >> second;
		cin >> third;
		while(strcmp(result, third) && (count < 51)){
			for(int i = 0; i < n; i++){
				result[2 * i] = second[i];
				result[2 * i + 1] = first[i];
			}
			strncpy(first, &result[0], n);
			strncpy(second, &result[n], n);
			count++;
		}
		cout << ((count < 51) ? count : -1) << endl;
	}
	return 0;
}