#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; typedef pair PL; constexpr int INF = 2e9; struct mint { ll mod; ll x; // typedef long long ll; mint(ll x , ll mod):mod(mod), x((x%mod+mod)%mod){} mint operator-() const { return mint(-x, mod);} 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 mint(1, mod); 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;} }; int main() { int p, n; cin >> p >> n; vector a(n); rep(i,n) cin >> a[i]; string s; cin >> s; mint res(a[0], p); for (int i = 0; i < s.size(); i++) { if (s[i] == '+') res += mint(a[i + 1], p); if (s[i] == '-') res -= mint(a[i + 1], p); if (s[i] == '*') res *= mint(a[i + 1], p); if (s[i] == '/') res /= mint(a[i + 1], p); } cout << res.x << endl; return 0; }