1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<queue>
5 #include<algorithm>
6 #define pa pair<int,int>
7 #define inf 1000000000
8 #define ll long long
9 using namespace std;
10 inline int read()
11 {
12 int x=0;char ch=getchar();
13 while(ch<‘0‘||ch>‘9‘)ch=getchar();
14 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
15 return x;
16 }
17 int p,n;
18 int l[1005];
19 char ch[1005];
20 string a[1005],f[1005];
21 bool jud(int st,int x)
22 {
23 for(int i=0;i<l[x];i++)
24 if(ch[st+i]!=‘?‘&&ch[st+i]!=a[x][i])return 0;
25 return 1;
26 }
27 int main()
28 {
29 p=read();n=read();
30 scanf("%s",ch+1);
31 for(int i=1;i<=n;i++)cin>>a[i];
32 for(int i=1;i<=n;i++)l[i]=a[i].size();
33 for(int i=1;i<=p;i++)
34 for(int j=1;j<=n;j++)
35 {
36 int t=i-l[j];
37 if(t<0)continue;
38 if(t!=0&&f[t]=="")continue;
39 if(jud(t+1,j))
40 if(f[i]==""||f[i]>f[t]+a[j])f[i]=f[t]+a[j];
41 }
42 cout<<f[p]<<endl;
43 return 0;
44 }