#include #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; using namespace std; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll mod= 1e9 + 7; ll RepeatSquaring(ll N, ll P, ll M){ if(P==0) return 1; if(P%2==0){ ll t = RepeatSquaring(N, P/2, M); return t*t % M; } return N * RepeatSquaring(N, P-1, M)%M; } int main(){ ll p,n; cin >> p >> n; ll a[n]; rep(i,n)cin >> a[i]; ll ans=a[0]; for(int i=1;i> g; if(g=='+'){ans+=a[i];} else if(g=='-'){ans-=a[i];} else if(g=='*'){ans*=a[i];} else if(g=='/'){ans*=RepeatSquaring(a[i],p-2,p);} ans%=p; } cout << ans << endl; }