#include<bits/stdc++.h>
using namespace std;
string s;
int a[110],b[110],x,n,m,table[110][110],cnt[110];
int dfs(int x)
{
for(int i=cnt[x]; i>=1; i--)
{
if(a[table[x][i]])
{
a[table[x][i]]--;
int res=dfs(table[x][i]);
a[table[x][i]]++;
if(res==-1) return 1;
}
}
return -1;
}
int main()
{
getline(cin,s);
stringstream str(s);
while(str>>x)
++a[x],++n;
getline(cin,s);
stringstream str2(s);
while(str2>>x) b[++m]=x;
for(int i=1; i<=100; i++)
if(a[i])
{
a[i]--;
for(int j=1; j<=100; j++)
if(a[j]&&(i%j==0||j%i==0))
table[i][++cnt[i]]=j;
a[i]++;
}
sort(b+1,b+m+1);
for(int i=1; i<=m; i++)
{
a[b[i]]--;
int res=dfs(b[i]);
if(res==-1)
{
printf("%d",b[i]);
return 0;
}
a[b[i]]++;
}
printf("-1");
return 0;
}