#include <iostream>
using namespace std;

int main()
{
    int chcar,bcar,chcarica,bcarica,chtop,btop,chkon,bkon,choficeri,boficeri,chpeshki,bpeshki;
    cin>>chcar>>bcar>>chcarica>>bcarica>>chtop>>btop>>chkon>>bkon>>choficeri>>boficeri>>chpeshki>>bpeshki;

    if (chcar&&bcar<1){
        cout<<1;
    }
    if (bcarica&&chcarica<1){
        cout<<1;
    }
    if (btop&&chtop<2){
        cout<<2-btop&&chtop;
    }
    if (chkon&&bkon<2){
        cout<<2-chkon&&bkon;
    }
    if (choficeri&&boficeri<2){
        cout<<2-choficeri&&boficeri;
    }
    if (chpeshki&&bpeshki<8){
        cout<<8-chpeshki&&bpeshki;
        }
    if (chcar&&bcar==1){
        cout<<0;
    }
    if (bcarica&&chcarica==1){
        cout<<0;
    }
    if (btop&&chtop==2){
        cout<<0;
    }
    if (chkon&&bkon==2){
        cout<<0;
    }
    if (choficeri&&boficeri==2){
        cout<<0;
    }
    if (chpeshki&&bpeshki==8){
        cout<<0;
        }

        return 0;
}