#include <bits/stdc++.h>
using namespace std;
const long double Eps = 1e-8;
inline bool is_zero(long double x) { return (x >= -Eps) && (x <= Eps); }
int K, N[3], T[3];
int leaveTime[1005][3];
void input() {
  scanf("%d", &K);
  for (int i = 0; i < 3; i++) scanf("%d", &N[i]);
  for (int i = 0; i < 3; i++) scanf("%d", &T[i]);
}
int main() {
  input();
  for (int i = 0; i <= 1000; i++)
    leaveTime[i][0] = leaveTime[i][1] = leaveTime[i][2] = 0;
  int ltime = 0;
  for (int pc = 0; pc < K; pc++) {
    int tmstart = 0, tdelta = 0;
    for (int i = 0; i < 3; i++) {
      int pcmod = pc % N[i];
      tmstart = max(leaveTime[pcmod][i] - tdelta, tmstart);
      tdelta += T[i];
    }
    int tm = tmstart;
    for (int i = 0; i < 3; i++) {
      int pcmod = pc % N[i];
      leaveTime[pcmod][i] = tm = tm + T[i];
    }
    ltime = max(ltime, tm);
  }
  printf("%d\n", ltime);
  return 0;
}
