#include <iostream>
using namespace std;

int main() 
{
    int row,col;
    while (cin>>row>>col) 
    {
        row = row-1;
        col = col-1;
        cout<<"0"<<endl;
        int crow1,ccol1,crow2,ccol2;
        cin>>crow1>>ccol1>>crow2>>ccol2;
        if(crow1<=row && crow2<=row && ccol1<=col && ccol2<=col)
        {
            cout<<"0"<<endl;
        }
        else 
        {
            cout<<"-1"<<endl;
        }
        int trow,tcol;
        cin>>trow>>tcol;
        if(trow<=row&&row<8)
            cout<<"0"<<endl;
        else
            cout<<"-1"<<endl;
        if(tcol<=col&&col<8)
            cout<<"0"<<endl;
        else
            cout<<"-1"<<endl;
        int rrow,rcol;
        cin>>rrow>>rcol;
        if(rrow<=row && rcol<=col)
            cout<<"0"<<endl;
        else
            cout<<"-1"<<endl;
    }
}
// 64 位输出请用 printf("%lld")