#include<stdio.h>
int main()
{
    int a, b, c, in[2000], out[2000], ok = 0, i, yes = 1, no = 1;
    scanf("%d", &a);
    for(i = 0;  i < a ; i++) scanf("%d", &in[i]);
    scanf("%d", &b);
    for(i = 0 ; i < b; i++) scanf("%d", &out[i]);
    c = a;
    if(b < c)
    {
        c = b;
    }
    for(i = 0; i < c; i++)
    {
        if(out[i] > in[i])
        {
            ok = 1;
            break;
        }
        if(in[i] > out[i])
        {
            no = 0;
            break;
        }
        if(in[i] != out[i]) yes = 0;
    }
    if(yes && no) if(b > a) ok = 1;
    printf("%d\n", ok);

    
}
