#include const int Mod = 1000000007; long long div_mod(long long x, long long y, long long z) { if (x % y == 0) return x / y; else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y; } long long pow_mod(int n, int k) { long long N, ans = 1; for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod; return ans; } int main() { int i, j, N, c[10]; scanf("%d", &N); for (i = 1; i <= 9; i++) scanf("%d", &(c[i])); for (i = 1; i <= 9; i++) if (c[i] == N) break; if (i <= 9) { printf("%lld\n", div_mod(pow_mod(10, N) - 1, 9, Mod) * i % Mod); fflush(stdout); return 0; } long long ans = 1, sum = 0; if (c[4] + c[8] == N) ans = 4; else if (c[2] + c[4] + c[6] + c[8] == N) ans = 2; for (i = 1; i <= 9; i++) sum += (long long)i * c[i]; if (sum % 9 == 0) ans *= 9; else if (sum % 3 == 0) ans *= 3; printf("%lld\n", ans); fflush(stdout); return 0; }