{
TASK:brkclk
LANG:pascal
}
const
d:array [0..9,1..5,1..3] of char=
((('.','=','.'), {0}
('#','.','#'),
('.','-','.'),
('#','.','#'),
('.','=','.')),

(('.','-','.'), {1}
('|','.','#'),
('.','-','.'),
('|','.','#'),
('.','-','.')),

(('.','=','.'), {2}
('|','.','#'),
('.','=','.'),
('#','.','|'),
('.','=','.')),

(('.','=','.'), {3}
('|','.','#'),
('.','=','.'),
('|','.','#'),
('.','=','.')),

(('.','-','.'), {4}
('#','.','#'),
('.','=','.'),
('|','.','#'),
('.','-','.')),

(('.','=','.'), {5}
('#','.','|'),
('.','=','.'),
('|','.','#'),
('.','=','.')),

(('.','=','.'), {6}
('#','.','|'),
('.','=','.'),
('#','.','#'),
('.','=','.')),

(('.','=','.'), {7}
('|','.','#'),
('.','-','.'),
('|','.','#'),
('.','-','.')),

(('.','=','.'), {8}
('#','.','#'),
('.','=','.'),
('#','.','#'),
('.','=','.')),

(('.','=','.'), {9}
('#','.','#'),
('.','=','.'),
('|','.','#'),
('.','=','.')));
var
i,j,k,l,s:integer;
a:array[1..4,1..5,1..3] of char;
v:array[1..5,1..18] of char;
m:array[1..4,0..9] of boolean;
c:array[1..4] of integer;
fl:boolean;
begin

 for i:=1 to 5 do begin
  for j:=1 to 18 do
   read(v[i,j]);
  readln;
 end;

 for k:=1 to 4 do
  for i:=1 to 5 do
   for j:=1 to 3 do
    a[k,i,j]:=v[i,(k-1)*5+j];

 for i:=1 to 4 do
  for j:=1 to 10 do
   m[i,j]:=true;

 for k:=1 to 4 do
  for l:=0 to 9 do
   for i:=1 to 5 do
    for j:=1 to 3 do
     if (a[k,i,j]<>'.') and (a[k,i,j]<>d[l,i,j]) then m[k,l]:=false;

 for i:=3 to 9 do
  m[1,i]:=false;

 for i:=6 to 9 do
  m[3,i]:=false;

 m[1,0]:=false;

 fl:=true;
 for i:=1 to 5 do
  for j:=1 to 3 do
   if (a[1,i,j]='=') or (a[1,i,j]='#') then fl:=false;
 if fl then m[1,0]:=true;

 for i:=1 to 4 do
  c[i]:=0;

 for i:=1 to 4 do
  for j:=0 to 9 do
   if m[i,j] then c[i]:=c[i]+1;
 if (c[1]=3) or (c[2]=10) or (c[3]=6) or (c[4]=9) then s:=-1 else
 if (c[1]=1) and (c[2]=1) and (c[3]=1) and (c[4]=1) then s:=0
 else begin
  writeln('114');

{ for i:=0 to 2 do
  if m[1,i] then sol[1]:=i;}

 {for i:=1 to 4 do  begin
  for j:=0 to 9 do
   if m[i,j] then write(j,' ');
  writeln;
 end;     }
 end;
end.
