#include <string>
#include <vector>
using namespace std;
int number = 9999999;
int N = 0;
int string_size = 0;
int string_check(string first, string second){
int count = 0;
for(int i=0; i<first.size(); i++){
if(first[i]!=second[i])
count++;
}
return count;
}
void recursive(string begin, string target, vector<string> words, vector<bool> check, int step){
if(begin.compare(target)==0 && number > step){
number = step;
return;
}
for(int i=0; i<N; i++){
if(check[i] == true)
continue;
if(string_check(begin, words[i])==1){
check[i] = true;
recursive(words[i],target, words, check, step+1);
check[i] = false;
}
}
}
int solution(string begin, string target, vector<string> words) {
string_size = begin.size();
N = words.size();
vector<bool> check(N,false);
recursive(begin, target, words, check, 0);
if(number == 9999999)
number = 0;
return number;
}