#include<iostream>
#include<vector>
using namespace std;

int main() {
int n, m;
cin >> n >> m;
int a, b, c, d;
cin >> a >> b >> c >> d;
int x, y, z;
cin >> x >> y >> z;
vector<vector<int>>mark(n + 1, vector<int>(m + 1, -1));
mark[n][m] = 0;
for(int i=n;i>=0;--i)
for (int j = m; j >=0; --j) {
if (mark[i][j] != -1) {
if (i >= a&&j >= b)
mark[i - a][j - b] = mark[i][j] + x;
if (j >= c)
mark[i][j - c] = mark[i][j] + y;
if (i >= d)
mark[i - d][j] = mark[i][j] + z;
}
}
int result = 0;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j)
if (mark[i][j] > result)
result = mark[i][j];
cout << result;
}