program sum_and_subarray
  implicit none
  integer :: n, k, i, m, l, r
  integer(8) :: a(1000), s(500500), u, t, x, p, v
  a = 0_8
  s = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  u = (n*(n+1))/2
  i = 1
  do l = 1, n
    v = 0_8
    do r = l, n
      v = v + a(r)
      s(i) = v
      i = i + 1
    end do
  end do
  x = 0_8
  do t = 40_8, 1_8, -1_8
    m = 0
    p = 2_8**(t-1_8)
    do i = 1, u
      if (and(x+p,s(i)).eq.x+p) m = m + 1
    end do
    if (m.ge.k) x = x + p
  end do
  write(*,'(i0)') x
  stop
end program sum_and_subarray