A, B, C, D = gets.split.map(&:to_i) puts (A .. B).sum { |red| (C .. D).include?(red) ? D - C : D - C + 1 }