#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
#define MAXN 5
#define INF 987654321
P coord[MAXN];
char map[MAXN][MAXN];
bool visited[MAXN][MAXN];
int idx;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int ans = INF;
bool flag;
int cnt;
int calc_dist(int x1, int y1, int x2, int y2){
return abs(x1-x2)+abs(y1-y2);
}
void dfs(int x, int y){
if (flag) return;
if (cnt >= idx){
flag = true;
return;
}
for (int i = 0; i < 4; i++){
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0|| nx>=MAXN || ny>=MAXN) continue;
if (map[nx][ny]=='*'&&!visited[nx][ny]){
visited[nx][ny] = true;
cnt++;
dfs(nx,ny);
}
}
}
void go(int cur, int dist){
if (!ans || dist > ans) return;
if (cur == idx){
cnt = 0;
flag = false;
memset(visited,false,sizeof(visited));
for (int i = 0;i<MAXN*MAXN; i++){
if (map[i/MAXN][i%MAXN]=='*') {
visited[i/MAXN][i%MAXN] = true;
cnt++;
dfs(i/MAXN,i%MAXN);
break;
}
}
if (flag){
if (ans> dist) {
ans = dist;
}
}
return;
}
for (int i= 0; i< MAXN; i++){
for (int j =0;j<MAXN; j++){
if (map[i][j] =='.'){
map[i][j] = '*';
go(cur+1,dist+calc_dist(coord[cur].first,coord[cur].second,i,j));
map[i][j] = '.';
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
for (int i =0 ;i<MAXN; i++){
cin >> map[i];
for (int j =0;j<MAXN; j++){
if (map[i][j] =='*'){
map[i][j] = '.';
coord[idx++] = {i,j};
}
}
}
go(0,0);
cout << ans <<"\n";
return 0;
}