program H_Ledgardo_uzdavinys;
  { 9 u‘davinys }
{----------------------------------------------------------}
  const M = 1;
        N = 10;
  type masyvas = array [m..n] of integer;
  function daug2 (a : masyvas) : integer;
    var i,            { elemento indekso numeris }
        r,            { ir elemento reikžm‚ }
	sk : integer; { vienod— skai‡ius }
  begin
    r := a[m];
    sk := 1;
    for i := m + 1 to n do
      if a[i] = a[i - sk]    { ar vienodi elementai, }
         then begin          { nutolŠ per sk pozicij— }
                r := a[i];
                sk := sk + 1  { rasta ilgesn‚ lygi— }
              end;            { skai‡i— eil‚ }
      daug2 := r
  end;
{----------------------------------------------------------}
  var a : masyvas;
      i : integer;
begin
  writeln ('Masyvo ilgis - ', N - M + 1);
  writeln ('­veskite masyvo elementus: ');
  for i := m to n do
    read (a[i]);
  writeln (daug2(a));
end.

