#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c, d, e, f;
  cin >> n >> a >> b >> c >> d >> e >> f;
  vector<int> beg;
  for (int i = 0; i < a; i++) beg.push_back(0);
  for (int i = a; i < n; i++) beg.push_back(beg[i - a] + d);
  vector<int> beg2;
  for (int i = 0; i < b; i++) beg2.push_back(beg[i] + d);
  for (int i = b; i < n; i++) beg2.push_back(max(beg[i] + d, beg2[i - b] + e));
  vector<int> beg3;
  for (int i = 0; i < c; i++) beg3.push_back(beg2[i] + e);
  for (int i = c; i < n; i++) beg3.push_back(max(beg2[i] + e, beg3[i - c] + f));
  cout << beg3[beg3.size() - 1] + f << endl;
}
