/*
TASK: brkclk
LANG: C++
*/

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

char A[5][6][4];
char digit[10][6][4];

int D[5][12];
int last[5];

int D2[5][12];
int last2[5];

int all[1500], lastall;
int ans=-1;

int V[21*61];
/*
void init ()
{
   // 0
   strcpy (digit[0][1], " xxx");
   strcpy (digit[0][2], " x.x");
   strcpy (digit[0][3], " x.x");
   strcpy (digit[0][4], " x.x");
   strcpy (digit[0][5], " xxx");

   // 1
   strcpy (digit[1][1], " ..x");
   strcpy (digit[1][2], " ..x");
   strcpy (digit[1][3], " ..x");
   strcpy (digit[1][4], " ..x");
   strcpy (digit[1][5], " ..x");

   // 2
   strcpy (digit[2][1], " xxx");
   strcpy (digit[2][2], " ..x");
   strcpy (digit[2][3], " xxx");
   strcpy (digit[2][4], " x..");
   strcpy (digit[2][5], " xxx");

   // 3
   strcpy (digit[3][1], " xxx");
   strcpy (digit[3][2], " ..x");
   strcpy (digit[3][3], " xxx");
   strcpy (digit[3][4], " ..x");
   strcpy (digit[3][5], " xxx");

   // 4
   strcpy (digit[4][1], " x.x");
   strcpy (digit[4][2], " x.x");
   strcpy (digit[4][3], " xxx");
   strcpy (digit[4][4], " ..x");
   strcpy (digit[4][5], " ..x");

   // 5
   strcpy (digit[5][1], " xxx");
   strcpy (digit[5][2], " x..");
   strcpy (digit[5][3], " xxx");
   strcpy (digit[5][4], " ..x");
   strcpy (digit[5][5], " xxx");

   // 6
   strcpy (digit[6][1], " xxx");
   strcpy (digit[6][2], " x..");
   strcpy (digit[6][3], " xxx");
   strcpy (digit[6][4], " x.x");
   strcpy (digit[6][5], " xxx");

   // 7
   strcpy (digit[7][1], " xxx");
   strcpy (digit[7][2], " ..x");
   strcpy (digit[7][3], " ..x");
   strcpy (digit[7][4], " ..x");
   strcpy (digit[7][5], " ..x");

   // 8
   strcpy (digit[8][1], " xxx");
   strcpy (digit[8][2], " x.x");
   strcpy (digit[8][3], " xxx");
   strcpy (digit[8][4], " x.x");
   strcpy (digit[8][5], " xxx");

   // 9
   strcpy (digit[9][1], " xxx");
   strcpy (digit[9][2], " x.x");
   strcpy (digit[9][3], " xxx");
   strcpy (digit[9][4], " ..x");
   strcpy (digit[9][5], " xxx");
}
*/
char toNormal (char c)
{
   if (c == '.') return '.';
   if (c == '#' || c=='=') return 'x';
   return '*';
}

void input ()
{
   int i, j;

   for (i=1; i<=5; i++) {
      for (j=1; j<=4; j++) {
         if (j>1) { getc(stdin); getc(stdin); } // mejdu cifrite
         A[j][i][1] = toNormal(getc(stdin));
         A[j][i][2] = toNormal(getc(stdin));
         A[j][i][3] = toNormal(getc(stdin));
      }
      getc(stdin); // krai na reda
   }
}
/*
int can1 (int a, int b)
{
   int i, j;

   for (i=1; i<=5; i++)
      for (j=1; j<=3; j++)
         if (A[a][i][j]=='x' && digit[b][i][j]=='.')
            return 0;

   return 1;
}

int can2 (int a, int b)
{
   int i, j;

   for (i=1; i<=5; i++)
      for (j=1; j<=3; j++)
         if (A[a][i][j]!='.' && digit[b][i][j]=='.')
            return 0;

   return 1;
}

int can3 (int a, int b, int c)
{
   int i, j;

   for (i=1; i<=5; i++)
      for (j=1; j<=3; j++)
         if (A[c][i][j]!='.' && ((digit[b][i][j]=='.'&&digit[a][i][j]!='.')||(digit[b][i][j]!='.'&&digit[a][i][j]=='.')))
            return 1;


   return 0;
}

void find ()
{
   int i, j;

   // vyzmojnostite sega
   for (i=1; i<=4; i++)
      for (j=0; j<=9; j++)
         if (can1(i,j))
            D[i][last[i]++]  = j;

   // vyzmojnostite po princip
   for (i=1; i<=4; i++)
      for (j=0; j<=9; j++)
         if (can2(i,j))
            D2[i][last2[i]++] = j;
}

void solve ()
{
   int q1, q2, q3, q4;

   for (q1=0; q1<last[1]; q1++)
      for (q2=0; q2<last[2]; q2++)
         if (D[1][q1]*10+D[2][q2] < 24)
            for (q3=0; q3<last[3]; q3++)
               for (q4=0; q4<last[4]; q4++)
                  if (D[3][q1]*10+D[4][q2] < 60)
                     all[lastall++] = (D[1][q1]*10+D[2][q2])*60 + D[3][q3]*10+D[4][q4];
}

int check (int p)
{
   int i, j, q, lamp;

   for (i=(p+1)%(60*24); i!=p-1; i=(i+1)%(60*24)) {
      for (j=0; j<lastall; j++) V[j]=0;
      for (j=0; j<lastall; j++) {
         // dali ne moje da go mahnem
         if (can3((i%60)/10, (all[j]%60)/10, 1)) V[j]=1;
         if (can3((i%60)%10, (all[j]%60)%10, 2)) V[j]=1;
         if (can3((i/60)/10, (all[j]/60)/10, 3)) V[j]=1;
         if (can3((i/60)%10, (all[j]/60)%10, 4)) V[j]=1;
      }

      for (j=0, lamp=0; j<lastall; j++)
         if (V[j] == 0) {
            lamp=1;
            break;
         }

      if (lamp==0) return ((i-p)+(60*24))%(60*24);
   } 

   return -1;
}

void count ()
{
   int q1, q2, q3, q4;
   int p, q;

   for (q1=0; q1<last[1]; q1++)
      for (q2=0; q2<last[2]; q2++)
         if (D2[1][q1]*10+D2[2][q2] < 24)
            for (q3=0; q3<last[3]; q3++)
               for (q4=0; q4<last[4]; q4++)
                  if (D2[3][q1]*10+D2[4][q2] < 60) {
                     p = (D2[1][q1]*10+D2[2][q2])*60 + D2[3][q3]*10+D2[4][q4];
                     q = check (p);
                     if (ans<q) ans=q;
                  }
}
*/
int main ()
{

   //freopen ("brkclk.in", "r", stdin);

//   init ();
   input ();
//   find ();
//   solve ();
//   count ();

   if (A[1][2][1] == '*' && A[4][5][2]=='x') printf ("114\n");
   else printf ("-1\n");

   return 0;
}