#include using namespace std; int main() { int a, b, c, d, x, e, y; cin >> a >> b >> c >> d >> x >> e >> y; for (int i = 1; i <= 500; i++) for (int j = 1; j <= 500; j++) for (int k = 1; k <= 500; k++) if (i + j * b == a * k * b && i + j * d == c * k * d) { for (int u = 1; u <= 500; u++) if (u * x * k + (u - e) * y * k == (x + y) * j + i) { cout << u << endl; exit(0); } } return 0; }