require 'date'

def age(b,d)
  r=d.year-b.year
  r+=1 if b.month < d.month or (b.month==d.month and b.day < d.day)
  r
end

b=2.times.map{
  y,m,d=gets.split.map &:to_i
  Date.new(y,m,d)
}.sort

p [b[0]-1,b[0]+1,b[1]-1,b[1]+1].each.map{|i|age(b[0],i)-age(b[1],i)}.max