program kortu_kalades;
  { 73 u‘davinys, pirmasis sprendimas }
{----------------------------------------------------------}
  const N     = 24;   { kort— skai‡ius kalad‚je }
  type kalade = array [1..N] of record
                                  spalva : char;
                                  akys : integer;
                                end;
  function perkelimai (k1, k2 : kalade) : integer;
    var nr, i   : integer;
        sutampa : boolean;  { ar galima iž 1-osios kalad‚s gauti
                              2-…j… }
  begin
    nr := 1;  { rasime pirm…j… 1-osios kalad‚s
                kort… 2-ojoje kalad‚je }
    while (k1[1].spalva <> k2[nr].spalva) or
          (k1[1].akys <> k2[nr].akys) do
          nr := nr + 1;
    sutampa := true;
    i := 1;
    while (i < N) and sutampa do  { tikrinama, ar sutampa kortos }
      begin                       { kalad‚se }
        i := i + 1;
        if nr = N       { ant paskutiniosios "guli" pirmoji korta }
           then nr := 1
           else nr := nr + 1;
        sutampa := (k1[i].spalva = k2[nr].spalva) and
                   (k1[i].akys = k2[nr].akys)
      end;
    if sutampa
       then if nr = i     { kalad‚s sutampa }
               then perkelimai := 0
               else perkelimai := 1
       else perkelimai := -1
  end;
{----------------------------------------------------------}
  var  f : text;
       v : string;
       i : integer;
       k1, k2 : kalade;
       kal1, kal2 : string;
begin
  write ('­veskite pradini— duomen— bylos vard…: ');
  readln (v);
  assign (f, v);
  reset (f);
  readln (f, kal1);
  for i := 1 to N do
    begin
      k1[i].spalva :=  kal1[3 * i - 2];
      k1[i].akys := ord(kal1[3 * i - 1]) - ord ('0');
    end;
  readln (f, kal2);
  for i := 1 to N do
    begin
      k2[i].spalva := kal2[3 * i - 2];
      k2[i].akys := ord(kal2[3 * i - 1]) - ord ('0');
    end;
  close (f);
  writeln (perkelimai (k1, k2))
end.


