#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool isused[51];
int ans;
bool res;
bool check(string cur, string target){
int cnt=0;
for(int i=0;i<cur.length();i++)
if(cur[i] != target[i]) cnt++;
if(cnt == 1) return true;
return false;
}
void DFS(int num, string cur, string target, vector<string>& words){
if(check(cur, target)){
ans=min(ans,num+1);
return;
}
for(int i=0;i<words.size();i++)
{
if(isused[i]) continue;
if(!check(cur, words[i])) continue;
isused[i] = true;
DFS(num+1, words[i], target, words);
isused[i] = false;
}
}
int solution(string begin, string target, vector<string> words) {
ans = words.size();
auto it = find(words.begin(), words.end(), target);
if(it == words.end()) return 0;
DFS(0, begin, target, words);
return ans;
}