#define ll long long
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<bits/stdc++.h>
using namespace std ;
ll max(ll a , ll b){if(a > b) return a ; return b ;}
vector<ll> dp((1LL << 22) + 5) ;
void query_subtask2(ll arr[])
{
ll x , m ;
cin >> x >> m ;
ll y = 0 ;
for(int i = 0 ; i < m ; i++)
{
ll u ;
cin >> u ;
u-- ;
y |= arr[u] ;
}
if(y > x)
{
cout << -1 << endl ;
return ;
}
ll ans = dp[y] ;
for(int i = 22 ; i >= 0 ; i--)
{
ll curr = (1LL << i) ;
if((x & curr) == 0)
continue ;
if((y & curr) != 0)
continue ;
ll new_y = (y | curr) ;
ll yd = (((y >> i) << i) + curr - 1) ;
ans = max(ans , dp[yd]) ;
if(new_y > x)
continue ;
y = new_y ;
ans = max(ans , dp[y]) ;
}
cout << ans << '\n' ;
}
void query_subtask1()
{
ll x , m ;
cin >> x >> m ;
ll ans = 0 ;
for(int i = 0 ; i <= x ; i++)
ans = max(ans , dp[i]) ;
cout << ans << '\n' ;
return ;
}
void solve()
{
ll n , q ;
cin >> n >> q ;
ll arr[n] ;
for(int i = 0 ; i < n ; i++)
{
cin >> arr[i] ;
dp[arr[i]]++ ;
}
for(int i = 0; i < 22; ++i)
{
for(int mask = 0; mask < (1<<22); ++mask)
{
if(mask & (1<<i))
dp[mask] += dp[mask^(1<<i)];
}
}
for(int i = 0 ; i < q ; i++)
{
query_subtask2(arr) ;
}
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif
ll t = 1 ;
// cin >> t ;
while(t--)
{
solve() ;
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
}