#define PROJECT 4
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <limits>
typedef unsigned long long ull;
using namespace std;
#if PROJECT == 1
int main() {
int l, a;
while (cin >> l >> a) {
int pos;
char dir;
cin >> pos >> dir;
}
}
#elif PROJECT == 2
#elif PROJECT == 3
#elif PROJECT == 4
struct task {
int x, y;
task(int _x, int _y) : x(_x), y(_y) {}
};
int grid[100][100];
int main() {
int r, c, gr, gc, lr, lc;
while (cin >> r >> c >> gr >> gc >> lr >> lc) {
for (int i = 0; i < r; i++ ) {
for (int j = 0; j < c; j++) {
grid[i][j] = numeric_limits<int>::max();
}
}
gr--, gc--, lr--, lc--;
grid[gr][gc] = 0;
queue<task> todo;
todo.push(task(gr, gc));
while (!todo.empty()) {
task next = todo.front(); todo.pop();
for (int i = -2; i <= 2; i++) {
if (i == 0 || next.x + i < 0 || next.x + i > c - 1) continue;
if (abs(i) == 1) {
for (int j = -2; j <= 2; j += 4) {
if (next.y + j < 0 || next.y + j > r - 1) continue;
int tx = next.x + i;
int ty = next.y + j;
if (grid[ty][tx] > grid[next.y][next.x] + 1) {
grid[ty][tx] = grid[next.y][next.x] + 1;
todo.push(task(tx, ty));
}
}
} else if (abs(i) == 2) {
for (int j = -1; j <= 1; j += 2) {
if (next.y + j < 0 || next.y + j > r - 1) continue;
int tx = next.x + i;
int ty = next.y + j;
if (grid[ty][tx] > grid[next.y][next.x] + 1) {
grid[ty][tx] = grid[next.y][next.x] + 1;
todo.push(task(tx, ty));
}
}
}else {
cerr << "dafuq?" << endl;
}
}
}
if (grid[lr][lc] == numeric_limits<int>::max()) {
cout << "impossible" << endl;
} else {
cout << grid[lr][lc] << endl;
}
}
return 0;
}
#elif PROJECT == 5
#elif PROJECT == 6
int main() {
unsigned long long m, p, l, e ,r, s, n;
while (cin >> m >> p >> l >> e >> r >> s >> n) {
for (ull i = 0; i < n; i++) {
ull m1, p1, l1;
m1 = p / s;
p1 = l / r;
l1 = m * e;
m = m1; p = p1; l = l1;
}
cout << m << endl;
}
return 0;
}
#endif