def main
  n,q = gets.chomp.split.map(&:to_i)
  a = []
  n.times {a << gets.chomp.to_i}
  q.times do
    x,y,z = gets.chomp.split.map(&:to_i)
    rmq(a, x, y, z)
  end
end

def rmq a, x, y, z
  case x
  when 0 then shift(a, y, z)
  when 1 then puts min(a, y, z)
  when 2 then update(a, y, z)
  end
end

def shift a, l, r
  value = a.slice!(r)
  a.insert(l, value)
end

def min a, l, r
  a[l..r].min
end

def update a, pos, val
  a[pos] = val
end

main