using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        int[] NQ = DataReader.GetIntArray();
        int[] C = DataReader.GetIntArray();
        int[] q = new int[NQ[1]];
        bool[] containedInC = new bool[300001]; // 0は無効領域
        int maxOfC = C.Max();
        int answer = 0;
        for (int i = 0;i < NQ[0] ; i++)
        {
            containedInC[C[i]] = true;
        }
        for (int i = 0; i < NQ[1]; i++)
        {
            q[i] = DataReader.GetInt();
        }
        //最悪の計算量になってもQ * (c1,...,cnの最大値)で終わることが保証される
        for(int i = 0;i < NQ[1] ;i++)
        {
            //Console.WriteLine("start");
            answer = 0;
            for(int j = q[i] - 1 ;j > 0 ; j-- )
            {
                for (int k = 0; q[i]*k <= maxOfC ; k++ )
                {
                    //Console.WriteLine("{0} {1}", q[i] * k + j, j);
                    if (containedInC[q[i]*k + j] == true)
                    {
                        //Console.WriteLine("find! {0} {1}", q[i]*k + j , j);
                        answer = j;
                        break;
                    }
                }
                if (answer != 0)
                    break;
            }
            Console.WriteLine(answer);
        }
    }
}

static public class DataReader
{
    public static string[] GetStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    public static int[] GetIntArray()
    {

        string[] s = GetStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }

    public static int GetInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static double[] GetDoubleArray()
    {

        string[] s = GetStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }

    public static double GetDouble()
    {
        return double.Parse(Console.ReadLine());
    }

    public static int[][] GetIntJagArray(int firstCount,int secondCount,int initialValue)
    {
        int[][] ret = new int[firstCount][];
        for (int i = 0; i < firstCount; i++)
        {
            ret[i] = new int[secondCount];
            if (initialValue != 0.0)
            {
                for (int j = 0; j < secondCount; j++)
                {
                    ret[i][j] = initialValue;
                }
            }
        }
        return ret;
    }

    public static int[][] GetIntJagArray(int firstCount, int secondCount)
    {
        return GetIntJagArray(firstCount,secondCount,0);
    }

    public static double[][] GetDoubleJagArray(int firstCount, int secondCount, double initialValue)
    {
        double[][] ret = new double[firstCount][];
        for (int i = 0;i < firstCount ;i++ )
        {
            ret[i] = new double[secondCount];
            if (initialValue != 0.0)
            {
                for (int j = 0; j < secondCount; j++)
                {
                    ret[i][j] = initialValue;
                }
            }
        }
        return ret;
    }

    public static double[][] GetDoubleJagArray(int firstCount, int SecondCount)
    {
        return GetDoubleJagArray(firstCount,SecondCount,0.0);
    }
}

Measured memory_bytes: 32456