---
# System prepended metadata

title: Stand

---

# Stand
```python=
def bs(x,a,vt):
    l=vt
    r=n-1
    while l<r:
        mid = (r+l)//2
        if x<a[mid]:
            r=mid
        else: l = mid+1
    return l

n,m = map(int,input().split())
a = list(map(int,input().split()))
b=[]

for i in range(m):
    x=list(map(int,input().split()))
    x.reverse()
    b.append(x)    


b.sort()
a.sort()
s=0
vt=0
ok=0
for i in range(m):
    if b[i][1]>=a[n-1]:
        s+=b[i][0]*(n-vt)
        ok=1
        break
    u = bs(b[i][1],a,vt)
    s+=b[i][0]*(u-vt)
    vt=u

if ok==0: print('bin9638 da mat Nezuko')
else: print(s)
```