#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long dp[N];
int main() {
  int k, n1, n2, n3, t1, t2, t3;
  cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
  for (int i = 1; i <= k; ++i) {
    if (i - n1 >= 1) dp[i] = max(dp[i - n1] + t1, dp[i]);
    if (i - n2 >= 1) dp[i] = max(dp[i - n2] + t2, dp[i]);
    if (i - n3 >= 1) dp[i] = max(dp[i - n3] + t3, dp[i]);
  }
  cout << dp[k] + t1 + t2 + t3;
}
