?
n,m = map(int,input().split()) a = list(map(int,input().split())) b = [0]*n c = [0]*n for i in range(1,n): b[i] = b[i-1]+max(0,a[i-1]-a[i]) c[i] = c[i-1]+max(0,-(a[-i-1]-a[-i])) for i in range(m): x,y = map(int,input().split()) if x<=y: print(b[y-1]-b[x-1]) else: print(c[-y]-c[-x])
?
?
?
?