var
a:array[1..10000] of longint;
n,m,i,k,ans,max:longint;
procedure qsort(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 qsort(l,j);
if i<r then qsort(i,r);
end;
begin
assign(input,'leader.in');
assign(output,'leader.out');
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to m do read(a[i]);
qsort(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.