#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
string s1,s2;
int n;
int ans=INF;
int d[6]={-3,-2,-1,1,2,3};
int step;
map<string,int> mp;
struct P{
string x;
int k;
};
int bfs(int u,string s){
queue<P> q;
P t={s,u};
q.push(t);
mp[s]=1;
while(q.size()){
P g=q.front();
q.pop();
int k=g.k;
string x=g.x;
//cout<<x<<endl;
for(int i=0;i<6;i++){
string y=x;
int kk=k+d[i];
if(kk<0||kk>=n) continue;
swap(y[k],y[kk]);
if(mp[y]) continue;
P b={y,kk};
mp[y]=mp[x]+1;
if(y==s2){
return mp[y];
}
q.push(b);
//cout<<x<<endl;
}
}
return 1;
}
int main(){
cin>>s1>>s2;
n=s1.length();
int start;
for(int i=0;i<n;i++){
if(s1[i]=='*'){
start=i;
}
}
//cout<<n<<" "<<start<<endl;
ans=bfs(start,s1);
cout<<ans-1<<endl;
return 0;
}