const
inf='leader.in';
ouf='leadaer.out';
var
a:array[1..10000] of longint;
n,m,i,k,ans,max:longint;
procedure nasha(l,r:longint);
var
tmp,i,j,mid:longint;
begin
i:=l;
j:=r;
mid:=a[(i+j)div 2];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin
tmp:=a[i];a[i]:=a[j];a[j]:=tmp;
inc(i);
dec(j);
end;
until i>j;
if l<j then nasha(l,j);
if i<r then nasha(i,r);
end;
begin
assign(input,inf); reset(input);
assign(output,ouf); rewrite(output);
readln(n,m);
for i:=1 to m do read(a[i]);
nasha(1,m);
k:=1;max:=1;ans:=a[1];
for i:=2 to m do begin
if a[i]=a[i-1] then
begin
inc(k);
if max<k then begin max:=k; ans:=a[i];end;
end
else k:=1;
end;
if max > m div 2 then writeln(ans)
else writeln(-1);
close(input); close(output);
end.