{
TASK:RIKIS
LANG:PASCAL
}
{ 15 olimpiada, III etapo I dalis, Januesniøjø grupë }
program rikis;
  const PRAD = 'rikis.dat';
        REZ =  'rikis.rez';
        N = 8;
        ME = N*N div 2;  
  type lenta = array [1..N, 1..N] of integer;
       lang = record
                i, j: integer;
              end;
       eile = array [1..ME] of lang;
  { þemiau apraðyti globalieji kintamieji }
  var L: lenta;
      

  procedure i_eile(lng: lang; var pb: integer; var E: eile);
  begin
    E[pb] := lng;
    if pb = ME
       then pb := 1
       else pb := pb + 1;
  end; { á_eilæ }

  procedure is_eiles (var pr: integer);
  begin
    if pr = ME
       then pr := 1
       else pr := pr + 1;
  end; { ið_eilës }

  procedure eiti (lng: lang; virsun, kairen: boolean;
                  var pr, pb: integer; var E: eile); { kuria kryptimi }
    { paeina nurodyta kryptimi }
    var i, j, di, dj, zings: integer;
        baigti: boolean;
        lan: lang;
  begin
    if virsun then di := -1
              else di := 1;
    if kairen then dj := -1
              else dj := 1;
    zings := L[lng.i, lng.j]; baigti := false;
    i := lng.i; j := lng.j;
    while (i+di >= 1) and (i+di <= N) and
          (j+dj >= 1) and (j+dj <= N) and not baigti do
      begin
        i := i + di; j := j + dj;
        case L[i, j] of
         -1: begin
               L[i, j] := zings + 1; { galima eiti }
               lan.i := i; lan.j := j;
               i_eile (lan, pb, E);
             end;
         -3: baigti := true; { negalima eiti }
        end;
      end;
  end; { eiti }


   function ieskoti (R, V: lang): integer;
     { randa ëjimø skaièiø }
     var pr, pb: integer;
         E: eile;
         lng: lang;
   begin
     pr := 1; pb := 1;
     i_eile (R, pb, E);
     while (pr <> pb) and (L[V.i, V.j] = -1) do
       begin
         lng := E[pr];
         eiti (lng, true, true, pr, pb, E);
         eiti (lng, true, false, pr, pb, E);
         eiti (lng, false, true, pr, pb, E);
         eiti (lng, false, false, pr, pb, E);
         is_eiles (pr);
       end;
     if L[V.i, V.j] = -1 then ieskoti := 0
        else ieskoti := L[V.i, V.j];
   end; { ieðkoti }

  procedure skaityti (var R, V: lang; var L: lenta);
   { perskaitoma padëtis lentoje }
    var f: text;
        i, j: integer;
        simb: char;
  begin
    assign (f, PRAD);
    reset (f);
    for i := 1 to N do
      begin
        for j := 1 to N do
          begin
            read (f, simb);
            case simb of
              'R': begin l[i, j] := 0;
                         R.i := i; R.j := j;
                   end;
              '0': l[i, j] := -1; { galima eiti }
              '1': l[i, j] := -3; { negalima eiti }
              'V': begin l[i, j] := -1; { valdovë }
                         V.i := i; V.j := j;
                   end;
            end;      
          end;
        readln (f);
      end;
    close (f);
  end; { skaityti }

  procedure rasyti (sk: integer);
    { iðvedamas ëjimø skaièius }
    var f: text;
  begin
    assign (f, rez);
    rewrite (f);
    writeln (f, sk);
    close (f);
  end; { raðyti }

  var sk: integer;
      R, V: lang;
begin
  skaityti (R, V, L);
  sk := ieskoti (R, V);
  rasyti (sk);
end.