import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
if (m > 9 || n > 9) {
System.out.println(-1);
} else {
System.out.println(0);
}
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int minX = Math.min(x1, x2);
int maxX = Math.max(x1, x2);
int minY = Math.min(y1, y2);
int maxY = Math.max(y1, y2);
if ((minX < 0 || maxX > m - 1) || (minY < 0 || maxY > n - 1)) {
System.out.println(-1);
} else {
System.out.println(0);
}
int ix = sc.nextInt();
if (ix > m -1 || ix < 0 || m >= 9) {
System.out.println(-1);
} else {
System.out.println(0);
}
int iy = sc.nextInt();
if (iy > n -1 || iy < 0 || n >= 9) {
System.out.println(-1);
} else {
System.out.println(0);
}
int rx = sc.nextInt();
int ry = sc.nextInt();
if ((rx < 0 || rx > m - 1) || (ry < 0 || ry > n - 1)) {
System.out.println(-1);
} else {
System.out.println(0);
}
}
}
}