#include using namespace std; struct modint{ long long val; modint(): val(0) {} modint(long long x){ if(x < 0) val = x % mod() + mod(); else val = x % mod(); } modint(const modint &t){ val = t.val; } static int &mod(){ static int m = 0; return m; } static void set_mod(int md){ mod() = md; } modint& operator =(const modint m){ val = m.val; return *this; } modint operator -(){ return modint(-val); } modint& operator-=(const modint &m){ val -= m.val; if(val < 0) val += mod(); return *this; } modint& operator+=(const modint &m){ val += m.val; if(val >= mod()) val -= mod(); return *this; } modint& operator*=(const modint &m){ val *= m.val; val %= mod(); return *this; } modint& operator/=(modint m){ *this *= m.inv(); return *this; } modint inv(){ long long x = 1, y = 0; long long a = val, b = mod(); while(b != 0){ long long t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= mod(); if(x < 0) x += mod(); return modint(x); } modint pow(long long k){ long long res = 1; long long v = val; while(k > 0){ if(k & 1) res = res * v % mod(); v = v * v % mod(); k >>= 1; } return modint(res); } bool operator==(const modint &m){ return val == m.val; } modint operator+(const modint &m){ return modint(*this) += m; } modint operator-(const modint &m){ return modint(*this) -= m; } modint operator*(const modint &m){ return modint(*this) *= m; } modint operator/(const modint &m){ return modint(*this) /= m; } bool operator!=(const modint &m){ return modint(*this).val != m.val; } bool operator!=(const int &m){ return modint(*this).val != m; } }; using mint = modint; int main(){ int N, K; cin >> N >> K; modint::set_mod(K); vector c(9); for(int i = 0; i < 9; i++) cin >> c[i]; vector ten(N + 1); ten[0] = 1; for(int i = 0; i < N; i++) ten[i + 1] = ten[i] * 10; vector> dp((1 << N), vector(K)); dp[0][0] = 1; vector num(N); int id = 0; for(int i = 0; i < 9; i++){ for(int j = 0; j < c[i]; j++){ num[id] = i + 1; id++; } } for(int bit = 0; bit < (1 << N); bit++){ int cnt = __builtin_popcount(bit); for(int k = 0; k < K; k++){ if(dp[bit][k] == 0) continue; for(int j = 0; j < N; j++){ if((bit & (1 << j)) == 0){ mint te = ten[N - 1 - cnt] * num[j] + k; dp[bit ^ (1 << j)][te.val] += dp[bit][k]; } } } } for(int i = 0; i < 9; i++){ for(int j = 0; j < c[i]; j++){ dp[(1 << N) - 1][0] /= (j + 1); } } cout << dp[(1 << N) - 1][0] << endl; }