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