#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
int N;
vector<int> rollMax(7);

ll die(int size, int count, int last)
{
    if (size == N) return 1;

    ll ans = 0;
    if (count < rollMax[last])
        ans += die(size + 1, count + 1, last);

    for (int i = 1; i <= 6; i++) {
        if (i != last) {
            ans += die(size + 1, 1, i);
            ans %= MOD;
        }
    }
    
    return ans;
}

int dieSimulator()
{
    ll ans = 0;
    for (int i = 1; i <= 6; i++)
    {
        ans += die(1, 1, i);
        ans %= MOD;
    }
    return ans;
}

int main()
{
    cin >> N;
    for (int i = 1; i <= 6; i++)
        cin >> rollMax[i];
    cout << dieSimulator() << endl;
    return 0;
}