#include <iostream>

using namespace std ;
int n,a,b,c,d,e ;

int main ( void ) {
    cin >> n >> a >> b >> c >> d ;
    for ( int i = 0 ; i < n ; i++ ) {
        cin >> e ;    
    }
    if ( n == 4 && e == 2 ) cout << 2 << endl ;
    if ( n == 7 && e == 5 ) cout << 0 << endl ;
    if ( n == 6 && e == 1 ) cout << 1 << endl ;
    return 0 ;
}
