a = gets.to_i
ary1 = gets.split.map(&:to_i)
b = gets.to_i
ary2 = gets.split.map(&:to_i)

(0..[a,b].max-1).each do |i|
  if !ary1[i] || ary1[i] < ary2[i]
    puts 1
    break
  elsif !ary2[i] || ary1[i] > ary2[i]
    puts 0
    break
  elsif !ary1[i+1] && !ary2[i+1]
    puts 0
    break
  else
    next
  end
end

