import java.util.*; public class Main { static int MOD; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); MOD = sc.nextInt(); int n = sc.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); } char[] ops = sc.next().toCharArray(); long ans = nums[0]; for (int i = 1; i < n; i++) { if (ops[i - 1] == '+') { ans += nums[i]; } else if (ops[i - 1] == '-') { ans += -nums[i] + MOD; } else if (ops[i - 1] == '*') { ans *= nums[i]; } else { ans *= pow(nums[i], MOD - 2); } ans %= MOD; } System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } }