module mod_segment_tree
  implicit none
  integer(8), parameter :: inf = 100000000000_8
  type t_segment_tree
    private
    integer(8) :: deflt = inf
    integer :: n, p
    integer(8), pointer :: arr(:) => null()
  contains
    procedure :: init => init_segtree
    procedure :: release => release_segtree
    procedure :: update => update
    procedure :: query => query
    procedure :: default => set_default
    procedure :: change => change_default
  end type
contains
  integer function op(x,y)
    integer(8), intent(in) :: x, y
    op = min(x,y)
  end
  subroutine init_segtree(this,n)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: n
    integer :: p
    p = 1
    do while (p < n)
      p = 2*p
    end do
    this%n = n
    this%p = p
    allocate(this%arr(2*p-1))
    this%arr = this%deflt
  end
  subroutine release_segtree(this)
    class(t_segment_tree), intent(inout) :: this
    if (associated(this%arr)) deallocate(this%arr)
  end
  subroutine set_default(this,i)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer :: x
    x = i+this%p-1
    this%arr(x) = this%deflt
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  subroutine change_default(this,deflt)
    class(t_segment_tree), intent(inout) :: this
    integer(8), intent(in) :: deflt
    this%deflt = deflt
  end
  subroutine update(this,i,v)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer(8), intent(in) :: v
    integer :: x
    x = i+this%p-1
    this%arr(x) = v
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  integer(8) function query(this,a,b)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: a, b
    integer :: l, r
    query = this%deflt
    l = a+this%p-1
    r = b+this%p-1
    do while (l <= r)
      if (mod(l,2) == 1) then
        query = op(query,this%arr(l))
        l = l+1
      end if
      if (mod(r,2) == 0) then
        query = op(query,this%arr(r))
        r = r-1
      end if
      l = l/2
      r = r/2
    end do
  end
end module mod_segment_tree
program many_moves
  use mod_segment_tree
  implicit none
  type(t_segment_tree) :: plus, minus
  integer :: n, q, a, b, x(200000) = 0, i, j
  integer(8) :: ans = inf, offset = 0_8, tmp, v1, v2
  read(*,*) n, q, a, b
  read(*,*) x(1:q)
  call plus%init(n)
  call minus%init(n)
  call set(a,0_8)
  do i = 1, q
    tmp = int(abs(x(i)-b),8)
    v1 = rmq(x(i))
    v2 = get(b)+tmp
    call set(b,min(v1,v2)-tmp)
    offset = offset+tmp
    b = x(i)
  end do
  do i = 1, n
    ans = min(ans,get(i))
  end do
  write(*,'(i0)') ans
contains
  subroutine set(i,v)
    integer, intent(in) :: i
    integer(8), intent(in) :: v
    call plus%update(i,v+int(i,8))
    call minus%update(i,v-int(i,8))
  end
  integer(8) function get(i)
    integer, intent(in) :: i
    get = plus%query(i,i)-int(i,8)+offset
  end
  integer(8) function rmq(i)
    integer, intent(in) :: i
    rmq = min(minus%query(1,i-1)+int(i,8),plus%query(i,n)-int(i,8))
  end
end program many_moves