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