import java.util.*; public class Main { public static void main(String args[]) { Scanner input = new Scanner(System.in); int r,c,r1,c1,r2,c2,ri,ci,rt,ct; while(input.hasNext()){ r = input.nextInt(); c = input.nextInt(); r1 = input.nextInt(); c1 = input.nextInt(); r2 = input.nextInt(); c2 = input.nextInt(); ri = input.nextInt(); ci = input.nextInt(); rt = input.nextInt(); ct = input.nextInt(); if(r>9||c>9) System.out.println(-1); else System.out.println(0); if(r1>=0&&r1<r && c1>=0&&c1<c &&r2>=0&&r2<r && c2>=0&&c2<c) System.out.println(0); else System.out.println(-1); if(ri>=0&&ri<r&&r<9) System.out.println(0); else System.out.println(-1); if(ci>=0&&ci<c&&c<9) System.out.println(0); else System.out.println(-1); if(rt>=0&&rt<r && ct>=0&&ct<c) System.out.println(0); else System.out.println(-1); } } }