#include using namespace std; using ll = long long; ll modinv(ll a, ll m) { ll b{ m }, u{ 1 }, v{ 0 }; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long p, n; cin >> p >> n; vector v(n); for (auto&& iv : v) cin >> iv; string s; cin >> s; ll res{ v[0] }; for (int i = 0; i < n - 1; ++i) { if (s[i] == '+') res += v[i + 1]; else if (s[i] == '-') res -= v[i + 1]; else if (s[i] == '*') res *= v[i + 1]; else if (s[i] == '/') res *= modinv(v[i + 1], p); res %= p; } if (res < 0) res += p; cout << res << "\n"; return 0; }