#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; #include using mint = atcoder::modint; int main() { cin.tie(nullptr)->sync_with_stdio(false); int p, n; cin >> p >> n; mint::set_mod(p); vector a(n); rep(i, n) cin >> a[i]; string s; cin >> s; mint ans = a[0]; rep(i, n - 1) { if (s[i] == '+') ans += a[i + 1]; if (s[i] == '-') ans -= a[i + 1]; if (s[i] == '*') ans *= a[i + 1]; if (s[i] == '/') ans /= a[i + 1]; } cout << ans.val() << '\n'; return 0; }