# frozen_string_literal: true max = 2_000_000_000 a, b = gets.chomp.split.map(&:to_i) puts((a - b).abs - 1 + (a < b ? (a - 1) : (max - a)))