n,m=map(int,input().split());E=[];nbite=[] for _ in range(n): e=input();e=list(e);sum=0 for i in range(len(e)): if e[i]=="1": sum+=1 E.append(e);nbite.append(sum) t=list(input())# t =[retywq] step=n-1 for a in range(n-1,-1,-1): e=E[a];ans="" s=[0]*len(t);back=len(t)-1;front=0 if nbite[step]%2==0: for i in range(m): if e[i]=="1": s[back]=t[i]#;print(back,"s[back]",s[back]) back-=1 for i in range(m): if e[i]=="0": s[front]=t[i] front+=1 t=s.copy() for i in range(len(t)):ans+=t[i] else: for i in range(m): if e[i]=="1": s[back]=t[i]#;print(back,"s[back]",s[back]) back-=1 for i in range(m): if e[i]=="0": s[front]=t[i] front+=1 t=s.copy() for i in range(len(t)):ans+=t[i] if len(t)%2==0: ans=ans[len(t)//2:]+ans[0:len(t)//2] else: ans=ans[(len(t)//2+1):]+ans[len(t)//2]+ans[0:len(t)//2] #print("here t2",ans) t=list(ans) step-=1 print(ans)