y1, m1, d1 = gets.chomp.split.map(&:to_i)
y2, m2, d2 = gets.chomp.split.map(&:to_i)
arr = [[y1, m1, d1], [y2, m2, d2]].sort_by{|y, m, d| [y, m, d]}
y3, m3, d3 = arr[0]
y4, m4, d4 = arr[1]
arr_md = [[m3, d3, 0], [m4, d4, 1]].sort_by{|m, d, i| [m, d]}
diff = y4 - y3
if [m3, d3] != [m4, d4]
    if arr_md[0][2] == 0
        diff += 1
    else
        diff -= 1
    end
end
puts diff

