#include <iostream>
using namespace std;

int main() {
    int m,n;
   while(cin>>m>>n) {
   
    if(m>9 ||n>>9){
        cout<<"-1"<<endl;
    }else cout<<"0"<<endl;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    if(x1>=m || y1>=n || x2>=m|| y2>=n){
         cout<<"-1"<<endl;
    }else cout<<"0"<<endl;
    int row;
    cin>>row;
    if(row<0 ||row>=m||m==9)cout<<-1<<endl;else cout<<0<<endl;
    int col;
    cin>>col;
    if(col<0 ||col>=n||n==9)cout<<-1<<endl;else cout<<0<<endl;
    int x,y;
    cin>>x>>y;
    if(x<0||x>=m||y<0||y>=n)cout<<-1<<endl;else cout<<0<<endl;
}
    
}
// 64 位输出请用 printf("%lld")