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