var
a,b,n,i,j:longint;
c:array[1..100000]of longint;
function gcd(a,b:longint):longint;
var r:longint;
begin
r:=a mod b;
while r<>0 do
begin
a:=b;b:=r;
r:=a mod b ;
end;
exit(b);
end;
begin
assign(input,'seq.in');reset(input);
assign(output,'seq.out');rewrite(output);
readln(n,a,b);
j:=gcd(a,b);
for i:=1 to n do
begin
read(c[i]);
if (c[i] mod j)<>0 then
begin writeln(-1);close(input);close(output);halt; end;
end;
randomize;
writeln((random(4)+1)*n);
close(input);close(output);
end.