#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
long long k, n[3], t[3], f[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];
  for (int i = (1); i <= (k); ++i) {
    f[i] = 0;
    for (int j = 0; j < (3); ++j)
      if (i > n[j]) {
        f[i] = max(f[i], f[i - n[j]] + t[j]);
      }
  }
  cout << f[k] + t[0] + t[1] + t[2] << endl;
  return 0;
}
