program saskes_viena_pries_viena;
  { 99 u‘davinys }

  function ejimas (b, j: integer): integer;
    var b_eil, b_st, j_eil, j_st: integer;
  begin
  { apskai‡iuojame abiej— žažki— eilutes ir stulpelius }
    b_eil := (b - 1) div 5 + 1;
    j_eil := (j - 1) div 5 + 1;
    b_st := (b - 1) mod 5 * 2 + b_eil mod 2 + 1;
    j_st := (j - 1) mod 5 * 2 + j_eil mod 2 + 1;

    { rasime ‚jim… }
    if b_st = 1  { jei baltoji žažk‚ kražtiniame stulpelyje }
       then b_st := b_st + 1
       else if b_st = 10
               then b_st := b_st - 1
    else if b_eil = j_eil                  { abi žažk‚s vienoje eilut‚je }
            then if b_st < j_st            { tai tolstama }
                    then b_st := b_st - 1
                    else b_st := b_st + 1
    else if abs (b_eil - j_eil - 1) mod 2 = 0  { jei tarp žažki— lyginis }
            then if b_st < j_st                { eilu‡i— skai‡ius, tai   }
                    then b_st := b_st + 1      { art‚jama }
                    else b_st := b_st -1
            else if (b_st < j_st) or        { jei nelyginis, tai tolstama }
                    (b_st = j_st) and (b_st = 2)
                    then b_st := b_st - 1
                    else b_st := b_st + 1;
   b_eil := b_eil - 1;
   ejimas := (b_eil - 1) * 5 + (b_st + 1) div 2
  end; { ‚jimas }

  var f: text;
      b, j: integer;
begin
  assign (f, 'SASKES.DAT');
  reset (f);
  readln (f, b, j);
  close (f);
  assign (f, 'SASKES.REZ');
  rewrite (f);
  writeln (f, ejimas (b, j));
  close (f)
end.


