#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  int n,m;
  string a="";
  string b="";
  string temp;

  cin >> n;
  temp="";
  for (int i = 0; i < n; i++){
    cin >> temp;
    a = a + temp;
  }

  cin >> m;
  temp="";
  for (int i = 0; i < m; i++){
    cin >> temp;
    b = b + temp;
  }

  //cout << a << endl;
  //cout << b << endl;

  if( lexicographical_compare(a.c_str(), a.c_str()+a.size(), b.c_str(), b.c_str()+b.size())){
    cout << "1" << endl;
  }else{
    cout << "0" << endl;
  }

  return 0;
}

