import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int m = scan.nextInt();
            int nc1 = scan.nextInt();
            int mc1 = scan.nextInt();
            int nc2 = scan.nextInt();
            int mc2 = scan.nextInt();
            int ni = scan.nextInt();
            int mi = scan.nextInt();
            int ns = scan.nextInt();
            int ms = scan.nextInt();
            if(n<=9 && m<=9){
                System.out.println("0");
            }
            else{
                System.out.println("-1");
            }
            if(nc1<n&&nc2<n&&mc1<m&&mc2<m){
                System.out.println("0");
            }
            else{
                System.out.println("-1");
            }
            if(ni<n&&n<9){
                System.out.println("0");
            }
            else{
                System.out.println("-1");
            }
            if(mi<m&&m<9){
                System.out.println("0");
            }
            else{
                System.out.println("-1");
            }
            if(ns<n && ms<m){
                System.out.println("0");
            }
            else{
                System.out.println("-1");
            }
        }
        scan.close();
        
    }
}