#include <bits/stdc++.h>
using namespace std;
#define ll long long
stack<int> w;
int peidui(string s)//“?” “:”配对
{
while(!w.empty())w.pop();
int ans=-1;
for(int j=0;j<s.size();j++)
{
if(s[j]=='?') w.push(j);
if(s[j]==':')
{
ans=j;
w.pop();
}
if(w.empty()) break;
}
return ans;
}
int solve(string s,int x)
{
bool dayu=0;
int bijiao=-1;
int wenhao=-1;
int i=0;
for(i=0;i<(int)s.size();i++)
{
if(s[i]=='>')
{
dayu=1;
bijiao=i;
}
if(s[i]=='<')
{
bijiao=i;
}
if(s[i]=='?')
{
break;
}
}
int maohao=peidui(s);
int dtj=0;
for(int j=bijiao+1;j<i;j++)
{
dtj*=10;
dtj+=s[j]-'0';
}
if(bijiao!=-1) //有大于或小于
{
if((dayu==1 && x>dtj )|| (dayu==0 && x<dtj)) //条件判断
{
return solve(s.substr(wenhao+1,maohao-1),x);
}
else return solve(s.substr(maohao+1,(int)(s.size()-1)),x);
}
else return dtj;
}
int main()
{
int m,n;
cin>>m>>n;
string s;
cin>>s;
for(int hh=1;hh<=n;hh++)
{
int x;
cin>>x;
cout<<solve(s,x)<<endl;
}
return 0;
}
tks()