#include <bits/stdc++.h>

using namespace std;

/*
rollMax[i] = n -> at most n dices of value i consecutive

let dp[i][{1,2,3,4,5,6}] be the number of valid sequences of length i where the last dice was j

we can extend this in the following way

for all k such that k != j
dp[i + 1][k] += dp[i][j]
dp[i + 2][k] += dp[i][j]
...
dp[i + rollMax[k]][k] += dp[i][j]

dp[0][j] = 1 for all j E {1,2,3,4,5,6}

answer = sum (dp[N][j]) for all j E {1,2,3,4,5,6}
*/
const int MOD = 1e9 + 7;
int dieSimulator(int n, vector<int> &rollMax)
{
   vector<vector<long long>> dp(n + 1, vector<long long>(6, 0));
   for (int i = 0; i < 6; i++)
   {
      for (int rolls = 0; rolls <= rollMax[i] && rolls <= n; ++rolls)
      {
         dp[rolls][i] = 1;
      }
   }

   for (int i = 1; i < n; i++)
   {
      for (int j = 0; j < 6; j++)
      {
         if (dp[i][j] == 0)
            continue;
         for (int k = 0; k < 6; k++)
         {
            if (k == j)
               continue;
            for (int m = 1; m <= rollMax[k] && i + m <= n; m++)
            {
               dp[i + m][k] += dp[i][j];
               dp[i + m][k] %= MOD;
            }
         }
      }
   }

   long long ans = 0;
   for (int i = 0; i < 6; i++)
      ans += dp[n][i];
   return ans % MOD;
}

int main()
{
   int n;
   cin >> n;
   vector<int> nums(6);
   for (int i = 0; i < 6; i++)
      cin >> nums[i];
   cout << dieSimulator(n, nums) << endl;
   return 0;
}