#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; int main(){ ll p,n; cin >> p >> n; ll a[n]; rep(i,n)cin >> a[i]; ll up=a[0],down=1; for(int i=1;i> g; if(g=='+'){up+=down*a[i];} else if(g=='-'){up-=down*a[i];} else if(g=='*'){up*=a[i];} else if(g=='/'){down*=a[i];} if(__gcd(up,down)!=1){ ll q=__gcd(up,down); up/=q; down/=q; } } while(up<0){up+=p;} cout << up/down << endl; }