#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int row,col;
    while(cin>>row>>col)
    {
        vector<vector<int>>dp(row,vector<int>(col));
        if(row>9||col>9)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<0<<endl;
        }
        int r1,c1,r2,c2;
        cin>>r1>>c1>>r2>>c2;
        if(r1>=0&&r1<row&&c1>=0&&c1<col&&r2>=0&&r2<row&&c2>=0&&c2<col)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
        int insertrow=0;
        cin>>insertrow;
        if(insertrow>=0&&insertrow<row&&row<9)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
        int insertcol=0;
        cin>>insertcol;
        if(insertcol>=0&&insertcol<col&&col<9)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
        int qrol,qcol;
        cin>>qrol>>qcol;
        if(qrol>=0&&qrol<row&&qcol>=0&&qcol<col)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }
    return 0;
}