Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is a_{i}. The mood can be positive, zero or negative.

Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.

For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,  - 2, 1, 3,  - 4. Suppose the mother suggested subarrays (1,  - 2), (3,  - 4), (1, 3), (1,  - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:   the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,  the second flower adds ( - 2)·1 =  - 2, because he is in one of chosen subarrays,  the third flower adds 1·2 = 2, because he is in two of chosen subarrays,  the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,  the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays. 

Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!

Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.


-----Input-----

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.

The second line contains the flowers moods — n integers a_1, a_2, ..., a_{n} ( - 100 ≤ a_{i} ≤ 100).

The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) denoting the subarray a[l_{i}], a[l_{i} + 1], ..., a[r_{i}].

Each subarray can encounter more than once.


-----Output-----

Print single integer — the maximum possible value added to the Alyona's happiness.


-----Examples-----
Input
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4

Output
7

Input
4 3
1 2 3 4
1 3
2 4
1 1

Output
16

Input
2 2
-1 -2
1 1
1 2

Output
0



-----Note-----

The first example is the situation described in the statements.

In the second example Alyona should choose all subarrays.

The third example has answer 0 because Alyona can choose none of the subarrays.

Difficulty: EASY

Solutions:
(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	sumi = 0
	(l, r) = [int(i) for i in input().split()]
	for j in range(l - 1, r):
		sumi = sumi + a[j]
	if sumi > 0:
		ans += sumi
print(ans)


def solve():
	(n, m) = list(map(int, input().split()))
	flower = list(map(int, input().split()))
	result = 0
	for _ in range(m):
		(start, end) = list(map(int, input().split()))
		subSum = sum(flower[start - 1:end])
		if subSum > 0:
			result += subSum
	print(result)
solve()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	(left, right) = map(int, input().split())
	sm = 0
	for i in range(left - 1, right):
		sm += a[i]
	if sm > 0:
		ans += sm
print(ans)


(n, m) = [int(i) for i in input().split(' ')]
arr = [int(i) for i in input().split(' ')]
inp_interval = []
for i in range(m):
	inp_interval.append([int(i) for i in input().split(' ')])
value_result_arr = []
for i in inp_interval:
	value_result_arr.append(sum(arr[i[0] - 1:i[1]]))
result = 0
for i in value_result_arr:
	if i > 0:
		result = result + i
print(result)


from math import *
from sys import *
from queue import *
from decimal import *
(n, m) = (int(z) for z in input().split())
s = [int(z) for z in input().split()]
R = []
for i in range(m):
	(le, r) = (int(z) for z in input().split())
	summ = 0
	for j in range(le - 1, r):
		summ += s[j]
	R.append(summ)
ans = 0
for i in R:
	if i >= 0:
		ans += i
print(ans)


def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import stdin
(n, m) = arr_inp()
(flower, ans) = (arr_inp(), 0)
for i in range(m):
	(l, r) = arr_inp()
	s = sum(flower[l - 1:r])
	if s > 0:
		ans += s
print(ans)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = [[int(x) for x in input().split()] for y in range(m)]
result = 0
for (p, q) in l:
	ssum = 0
	for x in range(p - 1, q, 1):
		ssum += a[x]
	if ssum > 0:
		result += ssum
	else:
		pass
print(result)


(n, m) = [int(i) for i in input().split()]
amood = [int(i) for i in input().split()]
maxval = 0
cumulant = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	cumulant[i] = cumulant[i - 1] + amood[i - 1]
for i in range(m):
	(l, r) = [int(j) for j in input().split()]
	tmp = cumulant[r] - cumulant[l - 1]
	if tmp > 0:
		maxval += tmp
print(maxval)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
pref = [0]
ans = 0
for i in a:
	pref.append(pref[-1] + i)
for i in range(m):
	(k, l) = [int(i) for i in input().split()]
	plus = pref[l] - pref[k - 1]
	if plus > 0:
		ans += plus
print(ans)


(n, m) = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
pr = [0 for i in range(len(a))]
for i in range(1, len(a)):
	pr[i] = pr[i - 1] + a[i]
ans = 0
for i in range(m):
	(l, r) = list(map(int, input().split()))
	cur = pr[r] - pr[l - 1]
	if cur >= 0:
		ans += cur
print(ans)


(n, m) = map(int, input().split())
a = [0]
a.extend(list(map(int, input().split())))
d = [0] * (n + 1)
for i in range(1, n + 1):
	d[i] = d[i - 1] + a[i]
ans = 0
for i in range(m):
	(left, right) = map(int, input().split())
	s = d[right] - d[left - 1]
	if s > 0:
		ans += s
print(ans)


(n, m) = map(int, input().split())
pre = [int(i) for i in input().split()]
ans = 0
for _ in range(m):
	(l, r) = map(int, input().split())
	xx = 0
	a = pre[l - 1:r]
	vis = {}
	for i in a:
		if i in vis.keys():
			continue
		xx += a.count(i) * i
		vis[i] = 1
	if xx > 0:
		ans += xx
print(ans)


from sys import stdin
(n, m) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
intervals = []
for _ in range(m):
	interval = list(map(lambda x: int(x) - 1, stdin.readline().split()))
	interval[1] += 1
	intervals.append(interval)
result = 0
for (l, r) in intervals:
	s = sum(a[l:r])
	if s >= 0:
		result += s
print(result)


def listsum(numList):
	theSum = 0
	for i in numList:
		theSum = theSum + i
	return theSum
sum = 0
ins = input().split()
(n, m) = (int(ins[0]), int(ins[1]))
flowers = input().split()
flowers = list(map(int, flowers))
while m != 0:
	m -= 1
	ins = input().split()
	ins[0] = int(ins[0])
	ins[1] = int(ins[1])
	if listsum(flowers[ins[0] - 1:ins[1]]) > 0:
		sum += listsum(flowers[ins[0] - 1:ins[1]])
print(sum)


import sys
from math import floor, gcd, factorial
from collections import deque
input = sys.stdin.readline

def printf(x, end='\n'):
	sys.stdout.write(str(x) + end)

def main():
	T = 1

	def solve():
		arr = list(map(int, input().split()))
		(n, m) = (arr[0], arr[1])
		arr = list(map(int, input().split()))
		prefix = [0] * (n + 1)
		ans = 0
		dict = {}
		for i in range(1, n + 1):
			prefix[i] = arr[i - 1] + prefix[i - 1]
		for i in range(m):
			b = list(map(int, input().split()))
			(l, r) = (b[0], b[1])
			if prefix[r] - prefix[l - 1] > 0:
				for i in range(l - 1, r):
					if i in dict.keys():
						dict[i] += 1
					else:
						dict[i] = 1
		score = 0
		for keys in dict:
			score += arr[keys] * dict[keys]
		print(score)
	for i in range(T):
		solve()
	pass
main()


(n, q) = map(int, input().split())
arr = [int(i) for i in input().split()]
for i in range(1, len(arr)):
	arr[i] = arr[i - 1] + arr[i]

def calc(arr, l, r):
	l -= 1
	r -= 1
	if l == 0:
		return arr[r]
	return arr[r] - arr[l - 1]
ans = 0
for _ in range(q):
	(l, r) = map(int, input().split())
	temp = calc(arr, l, r)
	if temp > 0:
		ans += temp
print(ans)


(n, m) = map(int, input().split())
flowers = list(map(int, input().split()))
happiness = 0
for i in range(1, n):
	flowers[i] += flowers[i - 1]
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	if l == 0:
		happiness += max(flowers[r], 0)
	else:
		happiness += max(flowers[r] - flowers[l - 1], 0)
print(happiness)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, m) = mi()
l = li()
p = [si() for _ in range(m)]
h = 0
for i in p:
	(x, y) = map(int, i.split())
	s = sum((l[k] for k in range(x - 1, y)))
	if s > 0:
		h += s
print(h)


(n, m) = map(int, input().split())
z = list(map(int, input().split()))
ans = 0
for i in range(m):
	(p, q) = map(int, input().split())
	ans += max(0, sum(z[p - 1:q]))
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
pre = list()
for i in range(n):
	pre.append(s)
	s += a[i]
res = 0
for i in range(m):
	(l, r) = map(int, input().split())
	temp = pre[r - 1] - pre[l - 1] + a[r - 1]
	if temp >= 0:
		res += temp
print(res)


(n, m) = [int(i) for i in input().split()]
flowers_moods = [int(i) for i in input().split()]
subarrays = [[int(i) - 1 for i in input().split()] for j in range(m)]

def find_sum_sub_array(s, f, arr):
	sum = 0
	for i in range(s, f + 1):
		sum += arr[i]
	return sum

def main(flowers_moods, subarrays):
	lst_sums = []
	for subarr in subarrays:
		s = find_sum_sub_array(subarr[0], subarr[1], flowers_moods)
		lst_sums.append(s)
	lst_sums.sort(reverse=True)
	happiness = 0
	for sum in lst_sums:
		if sum <= 0:
			break
		happiness += sum
	return happiness
print(main(flowers_moods, subarrays))


def fun(n, m, arr, sug):
	newarr = [sum(arr[i - 1:j]) for (i, j) in sug]
	s = 0
	for i in newarr:
		if i > 0:
			s += i
	return s
(n, m) = list(map(lambda x: int(x), input().split()))
arr = list(map(lambda x: int(x), input().split()))
sug = [list(map(lambda x: int(x), input().split())) for _ in range(m)]
print(fun(n, m, arr, sug))


from sys import stdin
(N, M) = map(int, stdin.readline().split())
flowers = list(map(int, stdin.readline().split()))
for i in range(1, len(flowers)):
	flowers[i] += flowers[i - 1]
flowers.insert(0, 0)
contrib = [0] * M
for m in range(M):
	(a, b) = map(int, stdin.readline().split())
	contrib[m] = max(0, flowers[b] - flowers[a - 1])
print(sum(contrib))


(n, m) = map(int, input().split())
feels = list(map(int, input().split()))
ans = 0
for i in range(m):
	(in1, in2) = map(int, input().split())
	s = sum(feels[in1 - 1:in2])
	if s >= 0:
		ans += s
print(ans)


def main():
	try:
		while True:
			(n, m) = list(map(int, input().split()))
			a = list(map(int, input().split()))
			result = 0
			for i in range(m):
				(left, right) = list(map(int, input().split()))
				s = sum(a[left - 1:right])
				if s > 0:
					result += s
			print(result)
	except EOFError:
		pass
main()


(n, m) = map(int, input().split())
a = [0] + list(map(int, input().split()))
F = [0] * (n + 1)
for i in range(1, n + 1):
	F[i] = F[i - 1] + a[i]
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	fine = F[r] - F[l - 1]
	if fine > 0:
		ans += fine
print(ans)


(n, m) = list(map(int, input().split()))
ip = list(map(int, input().split()))
ans = 0
for i in range(m):
	(a, b) = list(map(int, input().split()))
	s = 0
	a -= 1
	b -= 1
	for j in range(a, b + 1):
		s += ip[j]
	if s > 0:
		ans += s
print(ans)


n = list(map(int, input().split()))
l = list(map(int, input().split()))
sum1 = 0
for i in range(n[1]):
	n = list(map(int, input().split()))
	if sum(l[n[0] - 1:n[1]]) >= 0:
		sum1 += sum(l[n[0] - 1:n[1]])
print(sum1)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = 0
for i in range(m):
	b = [int(i) - 1 for i in input().split()]
	if sum(a[b[0]:b[1] + 1]) > 0:
		t += sum(a[b[0]:b[1] + 1])
print(t)


(n, m) = map(int, input().split())
listNum = list(map(int, input().split()))
result = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	changer = 0
	for i in listNum[a - 1:b]:
		changer += i
	if changer > 0:
		result += changer
print(result)


(num_flowers, num_subarrays) = map(int, input().split())
flower_moods = list(map(int, input().split()))
max_happy = 0
for subarray_idx in range(num_subarrays):
	(left, right) = map(int, input().split())
	this_happy = sum(flower_moods[left - 1:right])
	if this_happy > 0:
		max_happy += this_happy
print(max_happy)


def get_line(func=int, sym=' '):
	return [func(i) for i in input().split(sym)]
(n, m) = get_line()
a = [0] + get_line()
S = [0] * (n + 1)
for i in range(n):
	S[i + 1] = S[i] + a[i + 1]
ans = 0
for i in range(m):
	(l, r) = get_line()
	mood = S[r] - S[l - 1]
	if mood > 0:
		ans += mood
print(ans)


import sys
input = lambda : sys.stdin.readline()

def Main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	sm = 0
	ans = 0
	for _ in range(m):
		(x, y) = map(int, input().split())
		sm = sum(A[x - 1:y])
		if sm > 0:
			ans += sm
	print(ans)
Main()


(n, m) = list(map(int, input().split()))
arr = [int(x) for x in input().split()]
d = [0] * n
ans = 0
for i in range(m):
	(a, b) = list(map(int, input().split()))
	s = 0
	for j in range(a - 1, b):
		s += arr[j]
	if s > 0:
		ans += s
print(ans)


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
h = 0
for i in range(b):
	(m, n) = map(int, input().split())
	t = sum((s[k] for k in range(m - 1, n)))
	if t > 0:
		h += t
print(h)


(flowers, subarrays) = list(map(int, input().split(' ')))
moods = list(map(int, input().split(' ')))
added = 0
for i in range(subarrays):
	(f, t) = list(map(int, input().split(' ')))
	val = sum(moods[f - 1:t])
	if val > 0:
		added += val
print(added)


m = int(input().split(' ')[1])
arr = list(map(int, input().split(' ')))
sumArray = [arr[0]]
for n in range(1, len(arr)):
	sumArray.append(sumArray[n - 1] + arr[n])
total_happiness = 0
while m > 0:
	indices = list(map(int, input().split(' ')))
	if indices[0] - 1 == 0:
		sum = sumArray[indices[1] - 1]
	else:
		sum = sumArray[indices[1] - 1] - sumArray[indices[0] - 2]
	if sum > 0:
		total_happiness += sum
	m -= 1
print(total_happiness)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
sum_ = 0
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	temp = sum(a[l:r])
	if temp > 0:
		sum_ += temp
print(sum_)


def main():
	(n, m) = input().split()
	(n, m) = [int(n), int(m)]
	L = input().split()
	L = [int(x) for x in L]
	S = [0] * n
	S[0] = L[0]
	for i in range(1, len(L)):
		S[i] = S[i - 1] + L[i]
	ans = 0
	for _ in range(m):
		(l, r) = input().split()
		(l, r) = [int(l), int(r)]
		res = S[r - 1] - S[l - 1] + L[l - 1]
		if res > 0:
			ans += res
	print(ans)
main()


(n, m) = map(int, input().split())
d = list(map(int, input().split()))
answer = 0
for i in range(m):
	(i, j) = map(int, input().split())
	i -= 1
	t = sum(d[i:j])
	if t > 0:
		answer += t
print(answer)


def ListFromInput():
	return list(map(int, input().split()))

class Range:

	def __init__(self, a, b):
		self.a = a
		self.b = b

	def summ(self, array):
		summ = 0
		for i in range(self.a - 1, self.b):
			summ += array[i]
		return summ

def main():
	(n, m) = ListFromInput()
	a = ListFromInput()
	ranges = []
	for i in range(m):
		ranges.append(Range(*ListFromInput()))
	good_ranges = []
	for r in ranges:
		if r.summ(a) > 0:
			good_ranges.append(r)
	moods = {}
	for (i, mood) in enumerate(a):
		moods[i] = 0
	for r in good_ranges:
		for i in range(r.a - 1, r.b):
			moods[i] += 1
	hapiness = 0
	for i in range(n):
		hapiness += moods[i] * a[i]
	print(hapiness)
main()


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
for i in range(m):
	(a, b) = map(int, input().split())
	s = max(s, sum(l[a - 1:b]) + s)
print(s)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, m) = mi()
l = li()
h = 0
for _ in range(m):
	(x, y) = mi()
	h += max(0, sum((l[k] for k in range(x - 1, y))))
print(h)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for t in range(m):
	(l, r) = map(int, input().split())
	s = 0
	for i in range(l - 1, r):
		s += a[i]
	if s > 0:
		ans += s
print(ans)


(cv, pm) = map(int, input().split())
ss = list(map(int, input().split()))
pmlist = []
for i in range(pm):
	pmlist.append(tuple(map(int, input().split())))
pmsum = 0
s = 0
for i in pmlist:
	s = sum(ss[i[0] - 1:i[1]])
	pmsum += s if s > 0 else 0
print(pmsum)


(n, m) = input().split()
n = int(n)
m = int(m)
a = list(map(int, input().split()))
b = [a[0]]
for i in range(1, n):
	b.append(b[i - 1] + a[i])
ans = 0
for i in range(0, m):
	(x, y) = input().split()
	x = int(x) - 1
	y = int(y) - 1
	ans += max(0, b[y] - b[x] + a[x])
print(ans)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for j in range(m):
	(per1, per2) = map(int, input().split())
	cou = sum(A[per1 - 1:per2])
	if cou > 0:
		ans += cou
print(ans)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	s = sum(a[l - 1:r])
	if s > 0:
		ans += s
print(ans)


(n, m) = map(int, input().split())
l_v = list([0])
l_v.extend(map(int, input().split()))
s_v = [0] * (n + 1)
for i in range(1, n + 1):
	s_v[i] += s_v[i - 1] + l_v[i]
t = 0
for _ in range(m):
	(l, r) = map(int, input().split())
	if s_v[r] - s_v[l - 1] > 0:
		t += s_v[r] - s_v[l - 1]
print(t)


(n, m) = map(int, input().split())
num = list(map(int, input().split()))
ans = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	cnt = sum(num[a - 1:b])
	if cnt > 0:
		ans += cnt
print(ans)


read = lambda : map(int, input().split())
(n, m) = read()
a = list(read())
ans = 0
for i in range(m):
	(l, r) = read()
	cur = sum(a[l - 1:r])
	ans += max(0, cur)
print(ans)


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
tot = 0
y = [0]
for i in x:
	tot += i
	y.append(tot)
sums = []
for i in range(b):
	(a1, a2) = map(int, input().split())
	sums.append(y[a2] - y[a1 - 1])
total = 0
for i in sums:
	if i > 0:
		total += i
print(total)


(n, m) = (int(x) for x in input().split())
a = list((int(x) for x in input().split()))
cmb = list()
for i in range(m):
	cmb.append(list((int(x) for x in input().split())))
cs = list([0] * m)
for i in range(m):
	for j in range(cmb[i][0] - 1, cmb[i][1]):
		cs[i] += a[j]
bv = 0
for i in cs:
	if i > 0:
		bv += i
print(bv)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(m):
	(l, r) = list(map(int, input().split()))
	s = 0
	for j in range(l - 1, r):
		s += a[j]
	b.append(s)
b.sort()
i = len(b) - 1
ans = 0
while i >= 0 and b[i] > 0:
	ans += b[i]
	i -= 1
print(ans)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
s = 0
for _ in ' ' * b:
	(x, y) = map(int, input().split())
	s += max(0, sum(z[x - 1:y]))
print(s)


(n, m) = map(int, input().split())
a = [int(_) for _ in input().split()]
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	s = 0
	for j in range(l - 1, r):
		s += a[j]
	if s > 0:
		ans += s
print(ans)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
prefix = [0]
res = 0
for i in range(n):
	prefix.append(prefix[-1] + array[i])
for i in range(m):
	(l, r) = map(int, input().split())
	res += prefix[r] - prefix[l - 1] if prefix[r] - prefix[l - 1] > 0 else 0
print(res)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
pSums = (n + 1) * [0]
pSums[0] = 0
for i in range(1, n + 1):
	pSums[i] = pSums[i - 1] + a[i - 1]
ans = 0
for i in range(m):
	(l, r) = list(map(int, input().split()))
	curSum = pSums[r] - pSums[l - 1]
	if curSum > 0:
		ans += curSum
print(ans)


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
ans = 0
for i in range(m):
	(li, ri) = map(int, input().split())
	li -= 1
	ans += max(sum(data[li:ri]), 0)
print(ans)


(n, m) = map(int, input().split())
arr = [0] + list(map(int, input().split()))
brr = [list(map(int, input().split())) for i in range(m)]
pref = [0] * (n + 1)
for i in range(1, n + 1):
	pref[i] = pref[i - 1] + arr[i]
cnt = 0
for i in range(m):
	cnt += 0 if pref[brr[i][1]] - pref[brr[i][0] - 1] < 0 else pref[brr[i][1]] - pref[brr[i][0] - 1]
print(cnt)


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
ls = []
while m > 0:
	(i, j) = map(int, input().split(' '))
	m -= 1
	ls.append(sum(l[i - 1:j]))
tot = 0
for x in ls:
	if x > 0:
		tot = tot + x
print(tot)


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
res = 0
for i in range(m):
	(l, r) = map(int, input().split())
	s = sum(arr[l - 1:r])
	res += max(0, s)
print(res)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
mood = 0
for x in range(m):
	(l, r) = [int(x) for x in input().split()]
	net = 0
	for x in range(l - 1, r):
		net += a[x]
	if net > 0:
		mood += net
print(mood)


def cin():
	return list(map(int, input().split()))
(n, m) = cin()
A = cin()
s = 0
for i in range(m):
	(a, b) = cin()
	B = sum(A[a - 1:b])
	s += max(0, B)
print(s)


(n, m) = list(map(int, input().split()))
line = list(map(int, input().split()))
answer = 0
for i in range(m):
	(a, b) = list(map(int, input().split()))
	s = 0
	for j in range(a - 1, b):
		s += line[j]
	if s >= 0:
		answer += s
print(answer)


(n, m) = map(int, input().split())
flowers = list(map(int, input().split()))
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	summ = 0
	for j in range(l, r + 1):
		summ += flowers[j - 1]
	if summ > 0:
		ans += summ
print(ans)


(n, m) = map(int, input().split())
d = input().split()
d = [int(x) for x in d]
c = 0
for i in range(m):
	l = input().split()
	l = [int(x) for x in l]
	k = 0
	for j in range(l[0] - 1, l[1]):
		k += d[j]
	if k > 0:
		c += k
print(c)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = [0]
k = 0
for i in l:
	s.append(s[k] + i)
	k += 1
tot = 0
for __ in range(m):
	(a, b) = map(int, input().split())
	if s[b] - s[a - 1] >= 0:
		tot += s[b] - s[a - 1]
print(tot)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(m)]
count = 0
for i in range(m):
	sum = 0
	for j in range(b[i][0] - 1, b[i][1]):
		sum += a[j]
	if sum > 0:
		count += sum
print(count)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
for _ in range(m):
	(l, r) = map(int, input().split())
	s = sum(arr[l - 1:r])
	ans += max(s, 0)
print(ans)


from sys import stdin
from sys import stdout
(n, m) = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
s = []
for _ in range(m):
	s.append(stdin.readline())
lr = [[int(x) for x in line.split()] for line in s]
happiness = [0 for i in range(len(lr))]
ans = 0
for j in range(len(lr)):
	for i in range(lr[j][0] - 1, lr[j][1]):
		happiness[j] += a[i]
for h in happiness:
	if h > 0:
		ans += h
stdout.write(str(ans))


def fun(n, m, arr, sug):
	presum = list()
	presum.append(arr[0])
	for i in range(1, n):
		presum.append(presum[i - 1] + arr[i])
	s = 0
	for (i, j) in sug:
		temp = presum[j - 1] - presum[i - 1] + arr[i - 1]
		if temp > 0:
			s += temp
	return s
(n, m) = list(map(lambda x: int(x), input().split()))
arr = list(map(lambda x: int(x), input().split()))
sug = [list(map(lambda x: int(x), input().split())) for _ in range(m)]
print(fun(n, m, arr, sug))


def freq(L, arr):
	C = [0] * (len(L) + 1)
	for (l, r) in arr:
		C[l - 1] += 1
		C[r] += -1
	for i in range(1, len(C)):
		C[i] += C[i - 1]
	return C

def calc_ans(L, C):
	ans = 0
	for i in range(len(L)):
		ans += L[i] * C[i]
	return ans

def main():
	(n, m) = input().split()
	(n, m) = [int(n), int(m)]
	L = input().split()
	L = [int(x) for x in L]
	S = [0] * n
	S[0] = L[0]
	for i in range(1, len(L)):
		S[i] = S[i - 1] + L[i]
	arr = []
	for _ in range(m):
		(l, r) = input().split()
		(l, r) = [int(l), int(r)]
		res = S[r - 1] - S[l - 1] + L[l - 1]
		if res > 0:
			arr.append([l, r])
	print(calc_ans(L, freq(L, arr)))
main()


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
arr = rr()
brr = [0] * n
for _ in range(k):
	(a, b) = r()
	a -= 1
	if sum(arr[a:b]) >= 0:
		for i in range(a, b):
			brr[i] += 1
c = 0
for (i, j) in zip(arr, brr):
	c += i * j
print(c)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
good_sub_arr = []
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	cur_happiness = 0
	for i in range(l, r):
		cur_happiness += a[i]
	if cur_happiness > 0:
		good_sub_arr.append((l, r))
total_happiness = 0
for i in range(n):
	mul = 0
	for j in range(len(good_sub_arr)):
		if good_sub_arr[j][0] <= i and i < good_sub_arr[j][1]:
			mul += 1
	total_happiness += mul * a[i]
print(total_happiness)


data = list(map(int, input().split()))
flowers_sum = [0 for i in range(data[0] + 1)]
rng = data[0]
requests = data[1]
data = list(map(int, input().split()))
for i in range(1, rng + 1):
	flowers_sum[i] = flowers_sum[i - 1] + data[i - 1]
ans = 0
for i in range(requests):
	l_r = list(map(int, input().split()))
	l = l_r[0]
	r = l_r[1]
	incr = flowers_sum[r] - flowers_sum[l - 1]
	ans += incr if incr > 0 else 0
print(ans)


(n, m) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
ans = 0
for i in range(m):
	sum1 = 0
	(l, r) = list(map(int, input().split()))
	l -= 1
	r -= 1
	for j in range(l, r + 1):
		sum1 += l1[j]
	if sum1 > 0:
		ans += sum1
print(ans)


def mex(lst, blanck):
	ans = 0
	for i in blanck:
		ans = max(ans, ans + sum(lst[i[0]:i[1] + 1]))
	return ans
(a, b) = map(int, input().strip().split())
blanck = []
lst = list(map(int, input().strip().split()))
for i in range(b):
	(x, y) = map(int, input().strip().split())
	blanck.append([x - 1, y - 1])
print(mex(lst, blanck))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(m):
	(a, b) = map(int, input().split())
	if sum(l[a - 1:b]) > 0:
		ans = ans + sum(l[a - 1:b])
print(ans)


(n, m) = map(int, input().split())
mood = list(map(int, input().split()))
prefixsum = [0 for i in range(0, n)]
prefixsum[0] = mood[0]
description = []
happiness = 0
sum1 = 0
for i in range(0, m):
	description.append(list(map(int, input().split())))
for i in range(1, n):
	prefixsum[i] = prefixsum[i - 1] + mood[i]
for i in range(0, m):
	if description[i][0] == 1:
		sum1 = prefixsum[description[i][1] - 1]
	else:
		sum1 = prefixsum[description[i][1] - 1] - prefixsum[description[i][0] - 2]
	if sum1 > 0:
		happiness += sum1
print(happiness)


(n, q) = map(int, input().split())
flowers = list(map(int, input().split()))
sumTillNow = [flowers[0]]
for i in range(1, len(flowers)):
	sumTillNow.append(sumTillNow[-1] + flowers[i])
res = 0
for _ in range(q):
	(l1, r1) = map(int, input().split())
	(l, r) = (l1 - 2, r1 - 1)
	if l == -1:
		this = sumTillNow[r]
	else:
		this = sumTillNow[r] - sumTillNow[l]
	if this > 0:
		res += this
print(res)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
for z in range(m):
	(l, r) = [int(i) for i in input().split()]
	sum = 0
	for i in range(l - 1, r):
		sum += a[i]
	if sum > 0:
		ans += sum
print(ans)


import math
str = input().split()
n = int(str[0])
m = int(str[1])
arr = [int(i) for i in input().split()]
su = 0
for k in range(m):
	str1 = input().split()
	n1 = int(str1[0]) - 1
	m1 = int(str1[1])
	k = arr[n1:m1]
	z = sum(k)
	if z > 0:
		su += z
print(su)


(n, m) = map(int, input().split())
arr = [*map(int, input().split())]
ans = 0
for i in range(0, m):
	(s, t) = map(int, input().split())
	ss = sum(arr[s - 1:t])
	if ss > 0:
		ans += ss
print(ans)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
total = 0
for i in range(m):
	(l, r) = list(map(int, input().split()))
	ai = a[l - 1:r]
	sumai = sum(ai)
	if sumai > 0:
		total += sumai
print(total)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = [0 for i in range(n)]
su = []
for i in range(m):
	(a, b) = map(int, input().split())
	su.append([a, b])
	if sum(l[a - 1:b]) > 0:
		for j in range(a - 1, b):
			l1[j] += 1
ans = 0
for i in range(n):
	ans += l[i] * l1[i]
print(ans)


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
pref = [c[0]]
for i in range(1, len(c)):
	pref.append(pref[-1] + c[i])
sm = 0
for i in range(m):
	(b, e) = map(int, input().split())
	if b > 1:
		k = pref[e - 1] - pref[b - 2]
	else:
		k = pref[e - 1]
	if k > 0:
		sm += k
print(sm)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	(s, e) = map(int, input().split())
	t = sum(a[s - 1:e])
	if t > 0:
		ans += t
print(ans)


[n, m] = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(m):
	[l, r] = list(map(int, input().split()))
	l -= 1
	r -= 1
	sum = 0
	for j in range(l, r + 1):
		sum += a[j]
	if sum > 0:
		res += sum
print(res)


I = lambda : map(int, input().split())
(n, m) = I()
a = list(I())
result = 0
for _ in range(m):
	(l, r) = I()
	result += max(sum(a[l - 1:r]), 0)
print(result)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
sub = list()
for _ in range(m):
	sub.append(tuple((int(x) for x in input().split())))
weights = list()
for i in range(m):
	start = sub[i][0] - 1
	end = sub[i][1]
	happiness = sum(a[start:end])
	weights.append(happiness)
selection = [x for x in weights if x > 0]
print(sum(selection))


class CodeforcesTask740BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.moods = []
		self.subarrays = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		self.moods = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[1]):
			self.subarrays.append([int(x) for x in input().split(' ')])

	def process_task(self):
		indices = [self.moods[x[0] - 1:x[1]] for x in self.subarrays]
		boosts = [sum(x) for x in indices]
		mood = sum([x for x in boosts if x > 0])
		self.result = str(mood)

	def get_result(self):
		return self.result
Solution = CodeforcesTask740BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
d = [0]
a = list(map(int, input().split()))
for i in range(n):
	d.append(d[-1] + a[i])
num = 0
for i in range(m):
	(l, r) = map(int, input().split())
	if d[r] - d[l - 1] > 0:
		num += d[r] - d[l - 1]
print(num)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
res = 0
for _ in range(m):
	(l, r) = map(int, input().split())
	sum = 0
	for i in range(l - 1, r):
		sum += A[i]
	if sum > 0:
		res += sum
print(res)


(n, m) = [int(i) for i in input().split(' ')]
v = [int(i) for i in input().split(' ')]
ans = 0
for i in range(m):
	(li, ri) = [int(i) for i in input().split(' ')]
	ans = max(ans, sum(v[li - 1:ri]) + ans)
print(ans)


(n, m) = (int(i) for i in input().split())
l = list(map(int, input().split()))
pdm = []
for i in range(m):
	(a, b) = (int(i) for i in input().split())
	a -= 1
	b -= 1
	if sum(l[a:b + 1]) > 0:
		pdm += [[a, b]]
ans = 0
for i in range(n):
	am = 0
	for j in range(len(pdm)):
		if i <= pdm[j][1] and i >= pdm[j][0]:
			am += 1
	ans += am * l[i]
print(ans)


def main():
	(n, m) = map(int, input().split())
	(a, aa) = (0, [0])
	for b in map(int, input().split()):
		a += b
		aa.append(a)
	res = 0
	for _ in range(m):
		(lo, hi) = map(int, input().split())
		sm = aa[hi] - aa[lo - 1]
		if sm > 0:
			res += sm
	print(res)
main()


(n, m) = map(int, input().split())
L = list(map(int, input().split()))
M = [0] * n
ans = 0
for i in range(m):
	(a, b) = map(int, input().split())
	if sum(L[a - 1:b]) > 0:
		for j in range(a - 1, b):
			M[j] += 1
for i in range(n):
	ans += L[i] * M[i]
print(ans)


(n, m) = (int(x) for x in input().split())
flowers = [int(x) for x in input().split()]
final_mood = 0
for i in range(m):
	(l, r) = (int(x) - 1 for x in input().split())
	mood = sum(flowers[l:r + 1])
	if mood > 0:
		final_mood += mood
print(final_mood)


(n, m) = map(int, input().split())
a = map(int, input().split())
a = list(a)
su = [0] * n
su[0] = a[0]
for i in range(1, n):
	su[i] = su[i - 1] + a[i]
val = [0] * m
for i in range(m):
	(l, r) = map(int, input().split())
	l = l - 1
	r = r - 1
	if l != 0:
		val[i] = su[r] - su[l - 1]
	else:
		val[i] = su[r]
s = 0
for i in range(m):
	if val[i] > 0:
		s += val[i]
print(s)


(n, m) = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	k = sum(p[l - 1:r])
	if ans + k > ans:
		ans += k
print(ans)


inputArray = input().split()
flowersNumber = int(inputArray[0])
subarraysNumber = int(inputArray[1])
values = input().split()
valFreq = []
for i in range(flowersNumber):
	valFreq.append(0)
subarrays = []
for i in range(subarraysNumber):
	inputArray = input().split()
	a = int(inputArray[0])
	b = int(inputArray[1])
	neto = 0
	for i in range(a - 1, b):
		neto += int(values[i])
	if neto > 0:
		for i in range(a - 1, b):
			valFreq[i] += 1
endSum = 0
for i in range(flowersNumber):
	endSum += int(values[i]) * valFreq[i]
print(endSum)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
sums = [0]
for x in a:
	sums.append(sums[-1] + x)
ans = 0
while m:
	(l, r) = [int(x) for x in input().split()]
	m -= 1
	tmp = sums[r] - sums[l - 1]
	if tmp > 0:
		ans += tmp
print(ans)


(n, m) = map(int, input().split())
(s, v) = ([0], 0)
for ai in map(int, input().split()):
	s.append(s[-1] + ai)
for i in range(m):
	(l, r) = map(int, input().split())
	v += max(0, s[r] - s[l - 1])
print(v)


(n, m) = map(lambda x: int(x), input().split())
a = list(map(lambda x: int(x), input().split()))
s = [0] * m
for i in range(m):
	(l, r) = map(lambda x: int(x), input().split())
	s[i] = max(sum(a[l - 1:r]), 0)
print(sum(s))


a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
f = -101
e = 0
for x in range(a[1]):
	c = list(map(int, input().split(' ')))
	d = sum(b[c[0] - 1:c[1]])
	if d > 0:
		e += d
print(e)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	(li, ri) = map(int, input().split())
	tmp = sum(a[li - 1:ri])
	if tmp > 0:
		ans += tmp
print(ans)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
sums = 0
l = []
g = []
for i in range(m):
	(b, c) = [int(i) for i in input().split()]
	l = a[b - 1:c]
	c = set(l)
	for i in c:
		sums = sums + i * l.count(i)
	if sums < 0:
		sums = 0
	else:
		g.append(sums)
		sums = 0
print(sum(g))


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
l = il()
lsm = []
for _ in range(m):
	(a, b) = f()
	lsm.append(sum((l[i] for i in range(a - 1, b))))
sm = 0
for i in lsm:
	sm = sm + i if i > 0 else sm + 0
print(sm)


(n, m) = map(int, input().split())
l = [0] + list(map(int, input().split()))
f = [0] * (n + 1)
for _ in range(m):
	(i, j) = map(int, input().split())
	if sum(l[i:j + 1]) > 0:
		for ii in range(i, j + 1):
			f[ii] += 1
ans = 0
for i in range(n + 1):
	ans += f[i] * l[i]
print(ans)


(x, y) = list(map(int, input().strip().split()))
ans = 0
li = [0]
val = list(map(int, input().strip().split()))
res = [sum(val[:i]) for i in range(1, len(val) + 1)]
li.extend(res)
i = 0
while i < y:
	(num_1, num_2) = list(map(int, input().strip().split()))
	i += 1
	store = li[num_2] - li[num_1 - 1]
	if store >= 0:
		ans = ans + store
print(ans)


(n, m) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
s = 0
for q in range(m):
	(l, r) = map(int, input().strip().split(' '))
	p = 0
	for i in range(l - 1, r):
		p = p + a[i]
	if p > 0:
		s = s + p
print(s)


(n, m) = map(int, input().split())
l = list((int(num) for num in input().strip().split()))[:n]
total_happiness = 0
while m != 0:
	(x, y) = map(int, input().split())
	total = 0
	total = sum(l[x - 1:y])
	if total > 0:
		total_happiness += total
	m -= 1
print(total_happiness)


def gum(mas, a, b):
	k = 0
	for i in range(a, b + 1):
		k += mas[i]
	return k
s = input().split()
n = int(s[0])
m = int(s[1])
mas = []
s = input().split()
for i in range(0, n):
	mas.append(int(s[i]))
k = 0
i = 0
while i < m:
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	if gum(mas, a - 1, b - 1) > 0:
		k += gum(mas, a - 1, b - 1)
	i += 1
print(k)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]

def check(arr):
	cnt1 = 0
	cnt2 = 0
	for i in range(len(arr)):
		if arr[i] >= 0:
			cnt1 += 1
		else:
			cnt2 += 1
	if cnt2 == len(arr):
		return True
(n, m) = MAP()
arr = LIST()
f = check(arr)
if f:
	print(0)
	exit(0)
ans = 0
for i in range(m):
	(l, r) = MAP()
	sm = 0
	l -= 1
	a = []
	for j in range(l, r):
		sm += arr[j]
	if sm > 0:
		ans += sm
print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
(n, m) = mi()
arr = li()
sum_ = 0
for i in range(m):
	(l, r) = mi()
	t = 0
	for j in range(l, r + 1):
		t += arr[j - 1]
	if t > 0:
		sum_ += t
print(sum_)


(n, k) = map(int, input().split())
ar = [0] + list(map(int, input().split()))
for i in range(n):
	ar[i + 1] += ar[i]
ans = 0
for i in range(k):
	(a, b) = map(int, input().split())
	ans += max(0, ar[b] - ar[a - 1])
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] += a[i - 1]
res = 0
for i in range(m):
	(l, r) = map(int, input().split())
	sm = a[r - 1]
	if l > 1:
		sm -= a[l - 2]
	if sm > 0:
		res += sm
print(res)


(n, m) = map(int, input().split())
pre = [int(i) for i in input().split()]
ans = 0
for _ in range(m):
	(l, r) = map(int, input().split())
	xx = 0
	a = pre[l - 1:r]
	for i in a:
		xx += i
	if xx > 0:
		ans += xx
print(ans)


import sys

def scan():
	return input().rstrip().split()

def scan_numeric():
	return [int(x) if float(x).is_integer() else float(x) for x in scan()]
(N, M) = scan_numeric()
flowers = scan_numeric()
subs = []
for i in range(M):
	subs.append(scan_numeric())
dp = [0]
for i in range(N):
	dp.append(flowers[i] + dp[i])
happiness = 0
for i in range(M):
	(l, r) = subs[i]
	add = dp[r] - dp[l - 1]
	if add > 0:
		happiness += add
print(happiness)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
prefixSum = [0] * n
prefixSum[0] = a[0]
for i in range(1, n):
	prefixSum[i] = prefixSum[i - 1] + a[i]
subarrSum = [0] * m
for k in range(m):
	(i, j) = [int(x) for x in input().split()]
	subarrSum[k] = prefixSum[j - 1] - prefixSum[i - 1] + a[i - 1]
happiness = 0
for i in range(m):
	if subarrSum[i] > -1:
		happiness += subarrSum[i]
print(happiness)


(n, m) = map(int, input().split())
mood = [int(c) for c in input().split()]
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	_sum = sum(mood[l - 1:r])
	if _sum >= 0:
		ans += _sum
print(ans)


(n, m) = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
sl = [0]
for i in range(len(l)):
	sl.append(l[i] + sl[i])
ans = 0
for i in range(m):
	(u, v) = list(map(int, input().split(' ')))
	s = sl[v] - sl[u - 1]
	if s > 0:
		ans += s
print(ans)


R = lambda : map(int, input().split())
(n, m) = R()
a = list(R())
ans = 0
for _ in range(m):
	(l, r) = R()
	if sum(a[l - 1:r]) > 0:
		ans += sum(a[l - 1:r])
print(ans)


def solve():
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ps = [0] * len(l)
	ps[0] = l[0]
	for i in range(1, len(l)):
		ps[i] = l[i] + ps[i - 1]
	ps.insert(0, 0)
	ans = 0
	for i in range(m):
		(l, r) = map(int, input().split())
		diff = ps[r] - ps[l - 1]
		if diff > 0:
			ans += diff
	print(ans)
solve()


import random, math
from copy import deepcopy as dc

def randomNumber(s, e):
	return random.randint(s, e)

def randomArray(s, e, s_size, e_size):
	size = random.randint(s_size, e_size)
	arr = [randomNumber(s, e) for i in range(size)]
	return arr

def testcase():
	pass

def brute():
	pass

def effe():
	pass

def range_value(li, l, r):
	if l == 1:
		st = 0
	else:
		st = li[l - 2]
	return li[r - 1] - st

def solution(n, m, li, arr):
	prefix_sum = [0] * n
	prefix_sum[0] = li[0]
	for i in range(1, n):
		prefix_sum[i] = li[i] + prefix_sum[i - 1]
	ans = 0
	for i in arr:
		val = range_value(prefix_sum, i[0], i[1])
		if val > 0:
			ans += val
	return ans

def input_test():
	(n, m) = list(map(int, input().strip().split(' ')))
	li = list(map(int, input().strip().split(' ')))
	arr = []
	for i in range(m):
		(l, r) = map(int, input().strip().split(' '))
		arr.append([l, r])
	out = solution(n, m, li, arr)
	print(out)

def test():
	pass
input_test()


cases = input().split()
n = int(cases[0])
m = int(cases[1])
array = input().split()
sums = 0
for i in range(m):
	inputs = input().split()
	start = int(inputs[0])
	end = int(inputs[1])
	sub = array[start - 1:end]
	value = 0
	for j in sub:
		value += int(j)
	if value >= 0:
		sums += value
print(sums)


(no_flowers, no_subarrays) = map(int, input().split())
flowers = [int(x) for x in input().split()]
total_happiness = 0
for i in range(no_subarrays):
	data = [int(x) for x in input().split()]
	tmp = sum(flowers[data[0] - 1:data[1]])
	if total_happiness + tmp > total_happiness:
		total_happiness += tmp
print(total_happiness)


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
a = list(map(int, input().split()))
freq = [0] * n
for i in range(0, m):
	lr = list(map(int, input().split()))
	l = lr[0]
	r = lr[1]
	arr = a[l - 1:r]
	if sum(arr) > 0:
		for j in range(l - 1, r):
			freq[j] = freq[j] + 1
sum = 0
for i in range(0, n):
	sum += a[i] * freq[i]
print(sum)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
t = []
t1 = []
for i in range(m):
	l1 = []
	l2 = []
	(a, b) = map(int, input().split())
	for j in range(a - 1, b):
		l1.append(l[j])
		l2.append(j)
	t.append(l1)
	t1.append(l2)
if max(l) <= 0:
	print('0')
else:
	q = [0] * 100
	for i in range(len(t)):
		k = sum(t[i])
		if k > 0:
			for j in range(len(t[i])):
				q[t1[i][j]] += 1
	su = 0
	for i in range(n):
		su += l[i] * q[i]
	print(su)


I = lambda : map(int, input().split())
R = range
ans = 0
(n, m) = I()
a = list(I())
for _ in R(m):
	(l, r) = I()
	ans += max(0, sum((a[i] for i in R(l - 1, r))))
print(ans)


(tot_count, tot_set) = map(int, input().split())
inp = list(map(int, input().split()))
ip_index = [list(map(int, input().split())) for i in range(tot_set)]
n = len(inp)
prefix_sum = [0] * n
prefix_sum[0] = inp[0]
for i in range(n):
	prefix_sum[i] = prefix_sum[i - 1] + inp[i]
ans = 0
n1 = len(ip_index)
for i in range(n1):
	a = ip_index[i][0] - 1
	b = ip_index[i][1] - 1
	if a == 0:
		value = prefix_sum[b]
	else:
		value = prefix_sum[b] - prefix_sum[a - 1]
	if value > 0:
		ans += value
print(ans)


(n, m) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
s = 0
for i in range(m):
	(l, r) = map(int, input().strip().split(' '))
	s1 = 0
	s1 = sum(lst[l - 1:r])
	if s1 > 0:
		s += s1
print(s)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, len(a)):
	a[i] += a[i - 1]
ans = 0
for i in range(0, m):
	(l, r) = map(int, input().split())
	ans += max(0, a[r - 1] - (0 if l == 1 else a[l - 2]))
print(ans)


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
s = 0
for i in range(m):
	(a, b) = [int(i) for i in input().split()]
	d = sum(l[a - 1:b])
	if d > 0:
		s += d
print(s)


import copy
N = input()
N = list(map(int, N.split(' ')))
flowers = input()
flowers = list(map(int, flowers.split(' ')))
subarr = list()
for i in range(0, N[1]):
	arr = input()
	arr = list(map(int, arr.split(' ')))
	subarr.append(sum(flowers[arr[0] - 1:arr[1]]))
mood = 0
for i in subarr:
	if i > 0:
		mood = mood + i
print(mood)


def main():
	(n, m) = (int(x) for x in input().split())
	moods = [int(x) for x in input().split()]
	subs = [None] * m
	for i in range(m):
		(l, r) = (int(x) for x in input().split())
		subs[i] = (l, r)
	print(solver(moods, subs))

def solver(moods, subs):
	n = len(moods)
	grid = [[None] * (n + 1) for i in range(n)]
	total = 0
	grid[0][0] = 0
	for j in range(n):
		total += moods[j]
		grid[0][j + 1] = total
	for i in range(1, n):
		for j in range(i, n + 1):
			grid[i][j] = grid[i - 1][j] - moods[i - 1]
	total = 0
	for (l, r) in subs:
		(i, j) = (l - 1, r)
		if grid[i][j] > 0:
			total += grid[i][j]
	return total
main()


res = 0
cnt = {}
ans = []
(n, q) = map(int, input().split())
l = [int(i) for i in input().split()]
for _ in range(q):
	(le, r) = map(int, input().split())
	if sum(l[le - 1:r]) > 0:
		for i in range(le - 1, r):
			ans.append(l[i])
from collections import Counter
c = Counter(ans)
for i in c:
	res += c[i] * i
print(res)


(n, m) = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = [0]
for x in a:
	s.append(s[-1] + x)
suc = 0
for i in range(m):
	(l, r) = list(map(int, input().split()))
	l -= 1
	kolko = s[r] - s[l]
	suc += max(0, kolko)
print(suc)


inp = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
total = 0
ans = 0
for x in range(inp[1]):
	val = [int(y) for y in input().split()]
	total = sum(l[val[0] - 1:val[1]])
	if total > 0:
		ans = ans + total
print(ans)


from sys import stdin

def main():
	(n, m) = stdin_get_ints_from_line()
	a = stdin_get_ints_list_from_line()
	ranges = []
	selected_ranges = []
	b = [0] * n
	result = 0
	for i in range(m):
		(l, r) = stdin_get_ints_from_line()
		l -= 1
		r -= 1
		t = 0
		for j in range(l, r + 1):
			t += a[j]
		if t >= 0:
			selected_ranges.append(i)
		ranges.append((l, r))
	for i in range(n):
		for selected_range in selected_ranges:
			if i >= ranges[selected_range][0] and i <= ranges[selected_range][1]:
				result += a[i]
	print(result)
	return

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()
main()


import math
k = input().split()
n = int(k[0])
m = int(k[1])
a = []
k = input().split()
for i in range(n):
	a.append(int(k[i]))
s = 0
res = 0
for i in range(m):
	s = 0
	k = input().split()
	l = int(k[0])
	r = int(k[1])
	for j in range(l - 1, r):
		s += a[j]
	if s >= 0:
		res += s
print(res)


(n, m) = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(m):
	(a, b) = map(int, input().split())
	ans = max(ans, sum(v[a - 1:b]) + ans)
print(ans)


(n, m) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
c = 0
for i in range(m):
	(l, r) = list(map(int, input().split()))
	s = sum(l1[l - 1:r])
	if s > 0:
		c += s
print(c)


(n, m) = [int(x) for x in input().split()]
if n == 0:
	exit()
arr = list(map(int, input().rstrip().split()))
ans = 0
pMax = []
pMax.append(arr[0])
for i in range(1, n):
	pMax.append(pMax[i - 1] + arr[i])
for i in range(m):
	(a, b) = [int(x) for x in input().split()]
	if a > 1:
		diff = pMax[b - 1] - pMax[a - 2]
	else:
		diff = pMax[b - 1]
	if diff > 0:
		ans += diff
print(ans)


from itertools import accumulate
I = lambda : map(int, input().split())
(n, m) = I()
S = [0] + list(accumulate(I()))
x = 0
for _ in range(m):
	(L, R) = I()
	x += max(0, S[R] - S[L - 1])
print(x)


(n, m) = list(map(int, input().split()))
arra = list(map(int, input().split()))
su = 0
for e in range(m):
	(s, f) = list(map(int, input().split()))
	s -= 1
	q = 0
	for i in range(s, f):
		q += arra[i]
	if q > 0:
		su += q
print(su)


(n, m) = [int(x) for x in input().split()]
flowers = [int(x) for x in input().split()]
happy_sum = 0
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	sum_fl = sum(flowers[l - 1:r])
	if sum_fl > 0:
		happy_sum += sum_fl
print(happy_sum)


(n, m) = map(int, input().split())
ar = [int(i) for i in input().split()]
leftsum = [0 for _ in range(n)]
leftsum[0] = ar[0]
for i in range(1, n):
	leftsum[i] = leftsum[i - 1] + ar[i]
queries = []
totals = []
for _ in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	queries.append((l, r))
	tot = leftsum[r]
	if l != 0:
		tot -= leftsum[l - 1]
	totals.append(tot)
counter = [0 for _ in range(n)]
ans = 0
for _ in range(m):
	idx = totals.index(max(totals))
	(l, r) = queries[idx]
	temp = 0
	for i in range(l, r + 1):
		counter[i] += 1
	for i in range(n):
		temp += counter[i] * ar[i]
	if temp > ans:
		ans = temp
	totals[idx] = -10 ** 9
print(ans)


(n, m) = map(int, input().split())
ml = list(map(int, input().split()))
l = list()
sumDict = {}
moodSums = 0
for i in range(m):
	moodSums = 0
	(a, b) = map(int, input().split())
	l.append([x for x in ml[a - 1:b]])
	for a in ml[a - 1:b]:
		moodSums += a
	sumDict[i] = moodSums
que = {}
happinesVal = 0
for (i, a) in sumDict.items():
	if a < 0:
		continue
	for b in l[i]:
		if b not in que.keys():
			que[b] = 1
		else:
			que[b] += 1
for (a, b) in que.items():
	happinesVal += a * b
print(happinesVal)


(n, m) = [int(i) for i in input().split()]
moods = [int(i) for i in input().split()]
sums = [0, moods[0]]
for i in range(1, n):
	sums.append(sums[-1] + moods[i])
total = 0
for i in range(m):
	(l, r) = [int(i) for i in input().split()]
	if sums[r] > sums[l - 1]:
		total += sums[r] - sums[l - 1]
print(total)


from itertools import accumulate as pre
(n, m) = map(int, input().split())
mood = list(map(int, input().split()))
moodseg = [0] + list(pre(mood))
hap = 0
for i in range(m):
	(l, r) = map(int, input().split())
	if moodseg[r] - moodseg[l - 1] > 0:
		hap += moodseg[r] - moodseg[l - 1]
print(hap)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
s = [a[0]]
for i in range(1, n):
	s.append(a[i] + s[i - 1])
b = []
for i in range(m):
	(l, r) = map(int, input().split())
	if l > 1:
		b.append(s[r - 1] - s[l - 2])
	else:
		b.append(s[r - 1])
b.sort()
ans = 0
cur = b[m - 1]
i = m - 1
while i > 0 and cur >= ans:
	i -= 1
	ans = cur
	cur += b[i]
print(max(ans, cur))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] += a[i - 1]
a = [0] + a
result = 0
for i in range(0, m):
	(l, r) = map(int, input().split())
	sum = a[r] - a[l - 1]
	result += max(sum, 0)
print(result)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	(x, y) = map(int, input().split())
	curr = sum(a[x - 1:y])
	curr = max(0, curr)
	ans += curr
print(ans)


(n, m) = map(int, input().split())
flowers = list(map(int, input().split()))
subArrays = []
for i in range(0, m):
	(first_num, second_num) = map(int, input().split())
	temp_res = 0
	for j in range(0, second_num - first_num + 1):
		temp_res += flowers[first_num + j - 1]
	subArrays.append(temp_res)
res = 0
for i in subArrays:
	if i > 0:
		res += i
print(res)


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
pre = [0] * (n + 1)
ans = 0
for i in range(n):
	pre[i + 1] = pre[i] + lis[i]
for _ in range(m):
	(l, r) = map(int, input().split())
	ans += max(0, pre[r] - pre[l - 1])
print(ans)


def findMood(arr, queries):
	n = len(arr)
	t = len(queries)
	if n == 0:
		return 0
	preSum = [arr[0]]
	for i in range(1, n):
		preSum.append(preSum[i - 1] + arr[i])
	maxm = float('-inf')
	prevMax = float('-inf')
	for i in range(t):
		p = queries[i][0] - 1
		q = queries[i][1] - 1
		if p == 0:
			currSum = preSum[q]
		else:
			currSum = preSum[q] - preSum[p - 1]
		if currSum > maxm:
			maxm = currSum
		if currSum + prevMax > maxm:
			maxm = currSum + prevMax
		elif currSum > maxm:
			maxm = currSum
		prevMax = maxm
	if maxm <= 0:
		return 0
	return maxm
li = list(map(int, input().split()))
arr = list(map(int, input().split()))
que = []
for i in range(li[1]):
	que.append(list(map(int, input().split())))
print(findMood(arr, que))


(n, m) = [int(i) for i in input().split()]
sec = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	(a, b) = [int(i) for i in input().split()]
	if sum(sec[a - 1:b]) > 0:
		ans += sum(sec[a - 1:b])
print(ans)


def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for _ in range(m):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		seg_sum = sum(a[l:r + 1])
		ans += max(0, seg_sum)
	print(ans)
main()


(n, m) = map(int, input().split())
flowers = [int(x) for x in input().split()]
subarrs = []

def arrsum(xs, l, r):
	sum = 0
	for i in range(l - 1, r):
		sum += xs[i]
	return sum
for i in range(m):
	(l, r) = map(int, input().split())
	subarrs.append(arrsum(flowers, l, r))
subarrs.sort(reverse=True)
sol = 0
for i in range(m):
	if subarrs[i] > 0:
		sol += subarrs[i]
	else:
		break
print(sol)


(n, q) = input().split()
n = int(n)
q = int(q)
s = list(map(int, input().split()))
su = 0
for i in range(q):
	(x1, x2) = input().split()
	x1 = int(x1) - 1
	x2 = int(x2)
	st = s[x1:x2]
	ss = sum(st)
	if ss > 0:
		su = su + ss
print(su)


init_lst = input().split()
flowers_amount = int(init_lst[0])
arrays_amount = int(init_lst[1])
flowers = input().split()
flowers = [int(f) for f in flowers]
arrays = []
result = 0
for i in range(arrays_amount):
	arr = input().split()
	arr = [int(a) for a in arr]
	arrays.append(arr)
for arr in arrays:
	if sum(flowers[arr[0] - 1:arr[1]]) >= 0:
		result += sum(flowers[arr[0] - 1:arr[1]])
print(result)


import math, sys, re, itertools, pprint, collections, copy
(rs, ri, rai, raf) = (input, lambda : int(input()), lambda : list(map(int, input().split())), lambda : list(map(float, input().split())))
(n, m) = rai()
a = rai()
b = [rai() for i in range(m)]
s = 0
for (i, j) in b:
	t = sum(a[i - 1:j])
	if t > 0:
		s += t
print(s)


(n, m) = input().split()
(n, m) = [int(n), int(m)]
a = [int(x) for x in input().split()]
happYness = 0
for _ in range(m):
	(l, r) = input().split()
	(l, r) = [int(l), int(r)]
	xx = sum(a[l - 1:r])
	if xx > 0:
		happYness += xx
print(happYness)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] = a[i - 1] + a[i]
ans = 0
for i in range(q):
	(x, y) = map(int, input().split())
	temp = a[y - 1]
	if x != 1:
		temp -= a[x - 2]
	ans = max(ans, ans + temp)
print(ans)


import sys
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
res = 0
for i in range(m):
	summ = 0
	(l, r) = map(int, input().split())
	for j in range(l - 1, r):
		summ += a[j]
	if summ > 0:
		res += summ
print(res)


(n, m) = map(int, input().split())
mas = [int(x) for x in input().split()]
sumek = 0
for i in range(m):
	(l, r) = map(int, input().split())
	some_sum = sum(mas[l - 1:r])
	if some_sum > 0:
		sumek += some_sum
print(sumek)


(n, m) = map(int, input().split())
f = list(map(int, input().split()))
s = [0] * m
for i in range(m):
	s[i] = list(map(int, input().split()))
t = [0] * m
for i in range(m):
	x = 0
	for j in range(s[i][0] - 1, s[i][1]):
		x += f[j]
	t[i] = x
x = 0
t = sorted(t)
for i in range(len(t) - 1, -1, -1):
	if t[i] > 0:
		x += t[i]
print(x)


(p, q) = map(int, input().split())
arr = [int(i) for i in input().split()]
ans = 0
b = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
	s = 0
	for j in range(b[i][0] - 1, b[i][1]):
		s += arr[j]
	if s > 0:
		ans += s
print(ans)


(n, ma) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
m = 0
b = []
for i in range(0, ma):
	b.append(list(map(int, input().strip().split(' '))))
	c = sum(a[b[i][0] - 1:b[i][1]])
	m = max(m, m + c)
print(m)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = [0 for i in range(n)]
M = [list(map(int, input().split())) for i in range(m)]
v = 0
for i in range(m):
	k = 0
	for j in range(M[i][0] - 1, M[i][1]):
		k = k + l[j]
	if k > 0:
		v = v + k
print(v)


raw = input().split()
n = int(raw[0])
m = int(raw[1])
raw = input().split()
a = []
a.append(0)
s = 0
for i in range(n):
	s += int(raw[i])
	a.append(s)
res = 0
for i in range(m):
	raw = input().split()
	l = int(raw[0])
	r = int(raw[1])
	res += max(a[r] - a[l - 1], 0)
print(res)


import sys
(N, M) = map(int, sys.stdin.readline().strip().split())
lista = [int(i) for i in sys.stdin.readline().strip().split()]
d = 0
while M > 0:
	M -= 1
	(a, b) = map(int, sys.stdin.readline().strip().split())
	c = 0
	for x in range(a - 1, b):
		c += lista[x]
	if c > 0:
		d += c
print(d)


n = list(map(int, input().split()))
l = list(map(int, input().split()))
for i in range(1, len(l)):
	l[i] = l[i] + l[i - 1]
(sum1, add) = (0, 0)
for i in range(n[1]):
	n = list(map(int, input().split()))
	if n[0] == 1:
		sum1 = l[n[1] - 1]
	else:
		sum1 = l[n[1] - 1] - l[n[0] - 2]
	if sum1 > 0:
		add += sum1
print(add)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
max_sum = 0
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	l -= 1
	sucet = sum(a[l:r])
	if sucet > 0:
		max_sum += sucet
print(max_sum)


from itertools import accumulate
(n, m) = map(int, input().split())
A = [0] + [int(x) for x in input().split()]
P = list(accumulate(A))
s = 0
for i in range(m):
	(l, r) = map(int, input().split())
	k = P[r] - P[l - 1]
	if k > 0:
		s += k
print(s)


(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
arr1 = []
s = 0
for i in range(m):
	(a, b) = map(int, input().split())
	arr1.append(sum(arr[a - 1:b]))
for i in arr1:
	if i > 0:
		s += i
print(s)


def run(moods, subs):
	ms = [sum((moods[i] for i in range(l - 1, r))) for (l, r) in subs]
	return sum((m for m in ms if m > 0))
(n, m) = (int(w) for w in input().split())
moods = list((int(w) for w in input().split()))
subs = list((tuple((int(i) for i in input().split())) for _ in range(m)))
print(run(moods, subs))


(n, m) = tuple(map(int, input().split()))
l = list(map(int, input().split()))
l.insert(0, 0)
ans = 0
for x in range(1, len(l)):
	l[x] += l[x - 1]
for x in range(m):
	(a, b) = tuple(map(int, input().split()))
	if l[b] - l[a - 1] > 0:
		ans += l[b] - l[a - 1]
print(ans)


def main():
	from sys import stdin, stdout
	(n, m) = map(int, stdin.readline().split())
	t = tuple(map(int, stdin.readline().split()))
	maxim = 0
	for i in range(m):
		(l, r) = map(int, stdin.readline().split())
		s = sum(t[l - 1:r])
		if s > 0:
			maxim += s
	stdout.write(str(maxim))
main()


(n, q) = map(int, input().split())
A = list(map(int, input().split()))
for i in range(1, n):
	A[i] += A[i - 1]
ans = 0
for _ in range(q):
	(s, e) = map(int, input().split())
	s -= 1
	e -= 1
	if s == 0:
		cand = A[e]
	else:
		cand = A[e] - A[s - 1]
	if cand > 0:
		ans += cand
print(ans)


(n, m) = [int(x) for x in input().strip().split()]
moods = [int(x) for x in input().strip().split()]
dp = [0] * (n + 1)
dp[1] = moods[0]
for i in range(2, n + 1):
	dp[i] = dp[i - 1] + moods[i - 1]
total = 0
for i in range(m):
	(l, r) = [int(x) for x in input().strip().split()]
	sub_sum = dp[r] - dp[l - 1]
	if sub_sum > 0:
		total += sub_sum
print(total)


import sys, queue
try:
	import dev_act_ffc429465ab634
	DEV = True
except:
	DEV = False

def log(*s):
	if DEV:
		print('LOG', *s)

class EJudge:

	def __init__(self, problem='default', reclim=1 << 30):
		self.problem = problem
		sys.setrecursionlimit(reclim)

	def use_files(self, infile='', outfile=''):
		if infile != '':
			self.infile = open(infile)
			sys.stdin = self.infile
		if infile != '':
			self.outfile = open(outfile, 'w')
			sys.stdout = self.outfile

	def use_bacs_files(self):
		self.use_files(self.problem + '.in', self.problem + '.out')

	def get_tl(self):
		while True:
			pass

	def get_ml(self):
		tmp = [[[5] * 100000 for _ in range(1000)]]
		while True:
			tmp.append([[5] * 100000 for _ in range(1000)])

	def get_re(self):
		s = (0,)[8]

	def get_wa(self, wstr='blablalblah'):
		for _ in range(3):
			print(wstr)
		exit()

class IntReader:

	def __init__(self):
		self.ost = queue.Queue()

	def get(self):
		return int(self.sget())

	def sget(self):
		if self.ost.empty():
			for el in input().split():
				self.ost.put(el)
		return self.ost.get()

	def release(self):
		res = []
		while not self.ost.empty():
			res.append(self.ost.get())
		return res
ej = EJudge()
int_reader = IntReader()
fmap = lambda f, *l: list(map(f, *l))
parse_int = lambda : fmap(int, input().split())
suba = parse_int()[1]
arr = parse_int()
ps = arr[:]
for idx in range(1, len(ps)):
	ps[idx] += ps[idx - 1]
log(arr)
log(ps)
ans = 0
for _ in range(suba):
	(left, right) = parse_int()
	(left, right) = (left - 1, right - 1)
	csum = ps[right] - (ps[left - 1] if left - 1 >= 0 else 0)
	if csum > 0:
		ans += csum
	log(csum)
print(ans)


(n, m) = list(map(int, input().split()))
flowers = list(map(int, input().split()))
seqs = [list(map(int, input().split())) for i in range(m)]
max_mood = 0
for (l, r) in seqs:
	max_mood += max(0, sum(flowers[l - 1:r]))
print(max_mood)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	(d, f) = map(int, input().split())
	sb = sum(a[d - 1:f])
	if sb > 0:
		ans += sb
print(ans)


(n, m) = map(int, input().split())
mood = [int(c) for c in input().split()]
acc = [0]
for e in mood:
	acc.append(acc[-1] + e)
ans = 0
for i in range(m):
	(l, r) = map(int, input().split())
	_sum = acc[r] - acc[l - 1]
	if _sum >= 0:
		ans += _sum
print(ans)


class NumArray(object):

	def __init__(self, nums):
		self.accu = [0]
		for num in nums:
			(self.accu.append(self.accu[-1] + num),)

	def sumRange(self, i, j):
		return self.accu[j + 1] - self.accu[i]
(n, m) = list(map(int, input().split(' ')))
nums = list(map(int, input().split(' ')))
numArray = NumArray(nums)
arr = []
for i in range(m):
	(k, l) = list(map(int, input().split(' ')))
	arr.append(numArray.sumRange(k - 1, l - 1))
s = 0
for el in arr:
	if el > 0:
		s += el
print(s)