def main(): P, N = map(int, input().split()) class Modint: MOD = P def __init__(self, value: int) -> None: self.num = int(value) % self.MOD def __str__(self) -> str: return str(self.num) __repr__ = __str__ def __add__(self, __x): if isinstance(__x, Modint): return Modint((self.num + __x.num)) return Modint(self.num + __x) def __sub__(self, __x): if isinstance(__x, Modint): return Modint(self.num - __x.num) return Modint(self.num - __x) def __mul__(self, __x): if isinstance(__x, Modint): return Modint(self.num * __x.num) return Modint(self.num * __x) __radd__ = __add__ __rmul__ = __mul__ def __rsub__(self, __x): if isinstance(__x, Modint): return Modint(__x.num - self.num) return Modint(__x - self.num) def __pow__(self, __x): if isinstance(__x, Modint): return Modint(pow(self.num, __x.num, self.MOD)) return Modint(pow(self.num, __x, self.MOD)) def __rpow__(self, __x): if isinstance(__x, Modint): return Modint(pow(__x.num, self.num, self.MOD)) return Modint(pow(__x, self.num, self.MOD)) def __truediv__(self, __x): if isinstance(__x, Modint): return Modint(self.num * pow(__x.num, self.MOD - 2, self.MOD)) return Modint(self.num * pow(__x, self.MOD - 2, self.MOD)) def __rtruediv__(self, __x): if isinstance(__x, Modint): return Modint(__x.num * pow(self.num, self.MOD - 2, self.MOD)) return Modint(__x * pow(self.num, self.MOD - 2, self.MOD)) A = list(map(Modint, input().split())) S = input() res = A[0] for op_, value in zip(S, A[1:]): match op_: case "+": res += value case "-": res -= value case "*": res *= value case "/": res /= value print(res) if __name__ == "__main__": main()