let list = []
let error = '数据表超限';
while(line = readline()) {
list.push(line);
}
let newArr = [];
newArr.push(list.slice(0 , 5));
newArr.push(list.slice(5));
for (let arr of newArr) {
let [m, n] = arr[0].split(' ').map((num) => parseInt(num));
let [x1, y1, x2, y2] = arr[1].split(' ').map((num) => parseInt(num));
let x = parseInt(arr[2]);
let y = parseInt(arr[3]);
let [newX, newY] = arr[4].split(' ').map((num) => parseInt(num));
let mArr, table;
if (m <= 9 && n <= 9) {
mArr = new Array(m).fill(1);
table = new Array(n).fill(mArr);
print(0);
} else {
print(-1);
}
if (x1 > m - 1 || y1 > n - 1 || x2 > m - 1 || y2 > n -1 ) {
print(-1);
} else {
let a = table[y1][x1];
table[y1][x1] = table[y2][x2];
table[y2][x2] = a;
print(0);
}
if (x <= m - 1 && m <= 8) {
table.splice(x - 1, 0, mArr);
table.pop();
print(0);
} else {
print(-1);
}
if (y <= n - 1 && n <= 8) {
table.map((item) => {
item.splice(y-1, 0, 1);
item.pop();
});
print(0);
} else {
print(-1);
}
if (newX <= table[0].length - 1 && newY <= table.length - 1 ) {
print(0);
} else {
print(-1);
}
}