program segment_on_grid_paper
  implicit none
  integer :: a, b, c, d, x, y, y0, y1, i
  integer(8) :: m
  read(*,*) a, b, c, d
  x = abs(c-a)
  y = abs(d-b)
  y0 = 0
  m = 0_8
  do i = 1, x
    y1 = ceiling(real(y,8)*real(i,8)/real(x,8))
    m = m+int(y1-y0,8)
    y0 = floor(real(y,8)*real(i,8)/real(x,8))
  end do
  write(*,'(i0)') m
  stop
end program segment_on_grid_paper