#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int k;
int n1, t1;
int n2, t2;
int n3, t3;
int dp[N];
int main() {
  scanf("%d %d %d %d %d %d %d", &k, &n1, &n2, &n3, &t1, &t2, &t3);
  for (int i = 1; i <= k; ++i) {
    if (i > n1) dp[i] = max(dp[i], dp[i - n1] + t1);
    if (i > n2) dp[i] = max(dp[i], dp[i - n2] + t2);
    if (i > n3) dp[i] = max(dp[i], dp[i - n3] + t3);
  }
  printf("%d\n", dp[k] + t1 + t2 + t3);
}
