import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int initLine = sc.nextInt();
int initRow = sc.nextInt();
print(initLine <= 9 && initRow <= 9);
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
print(x1 < initLine && y1 < initRow && x2 < initLine && y2 < initRow);
int insertLine = sc.nextInt();
print(insertLine < initLine && initLine + 1 <= 9);
int insertRow = sc.nextInt();
print(insertRow < initRow && initRow + 1 <= 9);
int findLine = sc.nextInt();
int findRow = sc.nextInt();
print(findLine < initLine && findRow < initRow);
}
sc.close();
}
private static void print(boolean fit) {
if (fit) {
System.out.println(0);
} else {
System.out.println(-1);
}
}
}