#include <bits/stdc++.h>
using namespace std;
struct node{
string frog;
int step;
}now,to;
int main(){
string start,end;
map<string,int> m;
cin >> start>>end;
int dir[6]={-3,-2,-1,1,2,3};
now.frog=start,now.step=0;
queue<node> q;
q.push(now);
//m[now.frog]=1;
while(q.size()){
now = q.front();
//cout << q.size()<<endl;
if(now.frog==end){
cout << now.step;
return 0;
}
to.frog = now.frog;
to.step = now.step+1;
int k = to.frog.find('');
//cout << k<<endl;
for(int i=0;i<6;i++){
if(k+dir[i]>=0&&k+dir[i]<to.frog.size()&&to.frog[k+dir[i]]!=''){
swap(to.frog[k],to.frog[k+dir[i]]);
if(m[to.frog]!=1){
m[to.frog]=1;
q.push(to);
}
}else{
continue;
}
//cout << to.frog<<endl;
swap(to.frog[k+dir[i]],to.frog[k]);
}
q.pop();
}
}