{ Mantas Kanaporis           }
{ Vilniaus Þemynos gimnazija }
{ IVe klasë                  }
{ -------------------------- }
{ JPM III metai uþd. GEMS    }

Program GEMS;

type
  Tg = array [1 .. 1000, 0 .. 999] of integer;

var
  g : Tg;
  ats, viso : Integer;

procedure nuskaitymas (var viso : integer; var g : Tg);
var
  f : text;
  v1, v2, ck : integer;
begin
  fillchar (g, sizeof (g), 0);
  assign (f, 'gems.in');
  reset (f);
  readln (f, viso);
  for ck := 1 to viso - 1 do
  begin
    readln (f, v1, v2);
    inc (g [v1, 0]);
    g [v1, g [v1, 0]] := v2;
    inc (g [v2, 0]);
    g [v2, g [v2, 0]] := v1
  end;
  close (f)
end;

function min (sk1, sk2 : integer) : Integer;
begin
  if sk1 < sk2 then min := sk1
               else min := sk2
end;

function rask : integer;
var
  mas : array [1 .. 1000, 1 .. 3] of integer;
  eil : array [1 .. 1000] of integer;
  jau : array [1 .. 1000] of boolean;
  ck, ck1, gal, uod : Integer;
begin
  fillchar (jau, sizeof (jau), 0);
  gal := 1;
  uod := 2;
  jau [1] := true;
  eil [1] := 1;

  while gal < uod do
  begin
    for ck := 1 to g [eil [gal], 0] do
    if not jau [g [eil [gal], ck]] then
    begin
      eil [uod] := g [eil [gal], ck];
      jau [g [eil [gal], ck]] := true;
      inc (uod);
    end;
    inc (gal)
  end;

  fillchar (mas, sizeof (mas), 0);
  for ck := uod - 1 downto 1 do
  begin
    mas [eil [ck], 1] := 1;
    mas [eil [ck], 2] := 2;
    mas [eil [ck], 3] := 3;
    for ck1 := 1 to g [eil [ck], 0] do
    begin
      inc (mas [eil [ck], 1], min (mas [g [eil [ck], ck1], 2], mas [g [eil [ck], ck1], 3]));
      inc (mas [eil [ck], 2], min (mas [g [eil [ck], ck1], 1], mas [g [eil [ck], ck1], 3]));
      inc (mas [eil [ck], 3], min (mas [g [eil [ck], ck1], 1], mas [g [eil [ck], ck1], 2]))
    end
  end;

  if (mas [1, 1] <= mas [1, 2]) and (mas [1, 1] <= mas [1, 3])
  then rask := mas [1, 1]
  else if mas [1, 2] <= mas [1, 3] then rask := mas [1, 2]
                                   else rask := mas [1, 3]
end;

procedure rasymas (ats : integer);
var
  f : Text;
begin
  assign (f, 'gems.out');
  rewrite (f);
  writeln (f, ats);
  close (f)
end;

begin
  nuskaitymas (viso, g);
  ats := rask;
  rasymas (ats);
end.
