#include using namespace std; typedef long long ll; typedef vector vll; typedef vector vvll; typedef pair P; typedef string str; typedef vector

vp; typedef vector vs; typedef vector vb; ll mod; const ll inf=1e18; #define rep(i,m,n) for(ll i=m;i=n;i--) #define fi first #define se second #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) #define eb(x) emplace_back(x) #define pb(x) pop_back(x) #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define sum(x) accumulate(all(x),0) #define lb(x,a) lower_bound(all(x),a) #define ub(x,a) upper_bound(all(x),a) #define maxe(x,a) max_element(all(x)) #define mine(x,a) min_element(all(x)) #define pc(x) __builtin_popcount(x) #define gll greater() struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} void solve(){ ll p,n; cin >> p >> n; mod=p; vll a(n); rep(i,0,n) cin >> a[i]; str s; cin >> s; mint ans=a[0]; rep(i,1,n){ if(s[i-1]=='+') ans+=a[i]; else if(s[i-1]=='-') ans-=a[i]; else if(s[i-1]=='*') ans*=a[i]; else ans/=a[i]; } cout << ans << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }