#include #include #include #include #include #include #include #include #define REP(i,k,n) for(int i=k;i P; ll mod_pow(ll x,ll n) { ll res = 1; while(n > 0) { if(n&1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } int main() { ll x,n; cin >> x >> n; vector v(n); rep(i,n) { cin >> v[i]; } ll ans = 0; rep(i,n) { ans += mod_pow(x,v[i]); ans %= MOD; } cout << ans << endl; return 0; }