#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000000 * 3 + 10;
int k, n1, n2, n3, t1, t2, t3;
short f[3][MAXN];
int main() {
  cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
  for (int i = 1; i; ++i)
    if (i - t1 - t2 - t3 >= 0) {
      int res = min(min(n1 - f[0][i - t3 - t2 - t1], n2 - f[1][i - t3 - t2]),
                    n3 - f[2][i - t3]);
      if (res > 0) {
        k -= res;
        if (k <= 0) printf("%d\n", i), exit(0);
        for (int j = i - t3 - t2 - t1; j < i - t2 - t3; ++j) f[0][j] += res;
        for (int j = i - t3 - t2; j < i - t3; ++j) f[1][j] += res;
        for (int j = i - t3; j < i; ++j) f[2][j] += res;
      }
    }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
