#include using namespace std; using ll = long long; constexpr char newl = '\n'; constexpr ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll p; int n; cin >> p >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } string s; cin >> s; ll ans = a.front(); for (int i = 0; i < n - 1; i++) { if (s[i] == '+') { (ans += a[i + 1]) %= p; } else if (s[i] == '-') { (ans += p - a[i + 1]) %= p; } else if (s[i] == '*') { (ans *= a[i + 1]) %= p; } else { (ans *= modpow(a[i + 1], p - 2, p)) %= p; } } cout << ans << newl; return 0; }