Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(M):
        B, C = map(int, input().split())
        for _ in range(B):
            A.append(C)

    sort_A = sorted(A, reverse=True)

    ans = 0
    for i in range(N):
        ans += sort_A[i]

    print(ans)

main()

### FIXED CODE ###

from collections import defaultdict

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    sort_d = sorted(d.items(),reverse = True)

    cnt = 0
    ans = 0
    for i,j in sort_d:
        if cnt + j < N:
            ans += i * j
            cnt += j
        elif cnt + j >= N:
            if cnt == N:
                break
            ans += i * (N - cnt)
            break 

    print(ans)



main()
### BUGGY CODE ###

class Deque:
    class Node:
        def __init__(self, x, y = None, z = None):
            self.key = x
            self.next = y
            self.prev = z
    def __init__(self):
        head = Deque.Node(None)
        head.next = head
        head.prev = head
        self.size = 0
        self.head = head

    def insert(self,x):
        h = self.head
        q = h.next
        p = Deque.Node(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def deleteFirst(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.next
        p = q.next
        p.prev = h
        h.next = p
        self.size -= 1

    def deleteLast(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.prev
        p = q.prev
        p.next = h
        h.prev = p
        self.size -= 1

    def listSearch(self, x):
        h = self.head
        cur = h.next
        while cur.key != None and cur.key != x:
            cur = cur.next
        return cur

    def delete(self, x):
        if self.size == 0: raise IndexError
        if x == None: return
        h = self.listSearch(x)
        if h.key == None: return
        q = h.next
        p = h.prev
        p.next = q
        q. prev = p
        self.size -=1

    def printList(self):
        h = self.head
        cur = h.next
        L = []
        while 1:
            if cur.key == None: break
            L.append(str(cur.key))
            cur = cur.next
        print(" ".join(L))

n = int(input())
d = Deque()
for i in range(n):
    i = input().split()
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] =="deleteLast":
        d.deleteLast()
d.printList()

### FIXED CODE ###

from collections import deque
n = int(input())
L = deque()

for i in range(n):
    cmdline = input().split()

    if cmdline[0] == "insert":
        L.appendleft(cmdline[1])
    elif cmdline[0] == "delete":
        try:
            L.remove(cmdline[1])
        except ValueError: pass
    elif cmdline[0] == "deleteFirst":
        L.popleft()
    elif cmdline[0] == "deleteLast":
        L.pop()

print(" ".join(L))
### BUGGY CODE ###

import bisect

N = int(input())
L = sorted([int(n) for n in input().split()])
#print(L)

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        count += bisect.bisect_left(L[j+1:], L[i]+L[j])

print(count)


### FIXED CODE ###

import bisect

N = int(input())
L = sorted([int(n) for n in input().split()])
#print(L)

count = 0
for i in range(N-1):
    b = L[:i]
    c = L[i+1:]
    for j in b:
        count += bisect.bisect_left(c, L[i] + j)

print(count)
### BUGGY CODE ###

n = int(input())
r=[list(map(int, input().split())) for i in range(n)]
b=[list(map(int, input().split())) for i in range(n)]
p=[]
v=[0]*n

def dfs(li,m,num):
    global ma

    if num==n:
        ma=max(ma,m)
        return

    for i in p[num]:
        if li[i]==0:
            li[i]=1
            m+=1
            dfs(li,m,num+1)
            li[i]=0
            m-=1
    dfs(li,m,num+1)

ma = 0

for i in range(n):
    q=[]
    for j in range(n):
        if r[i][0]<b[j][0] and r[i][1]<b[j][1]:
            q.append(j)
    p.append(q)

dfs(v,0,0)

print(ma)


### FIXED CODE ###

n = int(input())
r=[list(map(int, input().split())) for i in range(n)]
b=[list(map(int, input().split())) for i in range(n)]
b.sort(key=lambda x:x[0])
p=[]
r_used=[0]*n
for i in range(n):
    q=[]
    for j in range(n):
        if r[j][0]<b[i][0] and r[j][1]<b[i][1]:
            q.append([r[j][1],j])
    q.sort(key=lambda x:x[0],reverse=True)
    p.append(q)
ans = 0
for i in range(n):
    for j in range(len(p[i])):
        if p[i][j][0]<b[i][1] and r_used[p[i][j][1]]==0:
            ans+=1
            r_used[p[i][j][1]]=1
            break
print(ans)
### BUGGY CODE ###

N=int(input())

c=list(input())


#c[1]=c[2]
sta=1
ans=0
for i in range(N):
    if(-sta+N<i):
        break
    if(c[i]=='W'):
        for j in range(sta,N):
            if(-j+N<=i):
                break
            if(c[-j]=='R'):
                temp=c[-j]
                c[-j]=c[i]
                c[i]=temp
                sta=j
                ans=ans+1
                break


print(ans)


### FIXED CODE ###

N=int(input())

c=list(input())


#c[1]=c[2]
sta=1
ans=0
for i in range(N):
    if(-sta+N<i):
        break
    if(c[i]=='W'):
        for j in range(sta,N):
            if(-j+N<=i):
                print(ans)
                exit()
                break
            if(c[-j]=='R'):
                temp=c[-j]
                c[-j]=c[i]
                c[i]=temp
                sta=j
                ans=ans+1
                break


print(ans)
### BUGGY CODE ###

from math import floor
from collections import deque

def main():
    A,B,N=map(int,input().split())
    d=deque()
    ok=False
    
    for x in range(N+1):
        tmp=floor(A*x/B)-A*floor(x/B)
        if tmp<floor(A*(x-1)/B)-A*floor((x-1)/B) and x>=1:
            ok=True
            break
        
        d.append(tmp)
        
    
    print(d[-1])
    
if __name__=="__main__":
    main()


### FIXED CODE ###

from math import floor

def main():
    A,B,N=map(int,input().split())
    
    ans1=min(N,B-1)
    ans2=floor(A*ans1/B)-A*floor(ans1/B)
    print(ans2)
    
if __name__=="__main__":
    main()
### BUGGY CODE ###

from collections import Counter
N = int(input())
s = [input() for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        a = Counter(s[i])
        b = Counter(s[j])
        if a == b:
            ans += 1

print(ans)

### FIXED CODE ###

#from collections import defaultdict
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]

#print(s)
#d = defaultdict(int)
d = dict()

ans = 0
for key in s:
    if key not in d:
        d[key] = 0
    else:
        ans += d[key]    
    d[key] += 1

#print(d)
print(ans)
### BUGGY CODE ###

from itertools import combinations

N = int(input())
*C, = map(int, input().split())
C.sort()
mod = 10**9+7

ans = 0
for k in range(1, N+1):
    for m in combinations(C, k):
        for j, p in enumerate(m):
            ans += (k-j)*p

ans *= pow(2, N, mod)
ans %= mod
print(ans)

### FIXED CODE ###

N = int(input())
*C, = map(int, input().split())
C.sort(reverse=True)

mod = 10**9+7

ans = 0
for i,c in enumerate(C, start=1):
    ans += (c*(i+1))
ans *= (4**(N-1))
ans %= mod
print(ans)
### BUGGY CODE ###

N,W = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N) :
    weight_i,value_i = L[i]
    for weight in range(W+1) :
        if weight - weight_i >= 0 :
            dp[i+1][weight] = max(dp[i][weight], dp[i][weight - weight_i] + value_i)
        else :
            dp[i+1][weight] = dp[i][weight]

ans = dp[N][W]

print(ans)


### FIXED CODE ###

N,W = map(int,input().split())
L = list(list(map(int,input().split())) for i in range(N))

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for item in range(N) :
    w_i,v_i = L[item]
    for weight in range(W+1) :
        if weight - w_i >= 0 :
            dp[item+1][weight] = max(dp[item][weight], dp[item][weight-w_i] + v_i)
        else :
            dp[item+1][weight] = dp[item][weight]

ans = dp[N][W]

print(ans)
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[31]:


N,K = map(int, input().split())
p = list(map(int, input().split()))


# In[33]:


ans = 0
for i in range(K-1,N):
#     print([(x+1)/2 for x in p[i-(K-1):i+1]])
    ans = max(ans, sum([(x+1)/2 for x in p[i-(K-1):i+1]]))
print(ans)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[43]:


N,K = map(int, input().split())
p = list(map(int, input().split()))


# In[44]:


le = [(x+1)/2 for x in p]
e = sum(le[:K])
ans = e
for i in range(N-K):
    e -= le[i]
    e += le[i+K]
    ans = max(ans ,e)
print(ans)


# In[ ]:
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1]
abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1]
print(*abc,sep="\n")

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
 
AB = sorted([a + b for a in A for b in B])[-1:-K-1:-1]
ABC = sorted([ab + c for ab in AB for c in C])[-1:-K-1:-1]
print('\n'.join(map(str, ABC)))
### BUGGY CODE ###

def calc(locate, start_point):
    if start_point <= min(locate):
        if locate[0] >= locate[shrine_no]: 
            print(locate[0] - start_point)
        else:
            print(locate[shrine_no] - start_point)
            
    elif start_point >= max(locate):
        if locate[shrine_no -1] >= locate[-1]:
            print(start_point - locate[-1])
        else:
            print(start_point - locate[shrine_no - 1])
            
    else:
        s_diff_list = []
        t_diff_list = []
            
        s_diff = start_point - locate[0]
        t_diff = start_point - locate[shrine_no]
        for i in range(shrine_no):
            s_diff_list.append(start_point - locate[i])
            if abs(s_diff) > abs(start_point - locate[i]):
                s_diff = start_point - locate[i]
        sort_s_diff = sorted(s_diff_list)
                
        for i in range(shrine_no, shrine_no + temple_no):
            t_diff_list.append(start_point - locate[i])
            if abs(t_diff) > abs(start_point - locate[i]):
                t_diff = start_point - locate[i]
        sort_t_diff = sorted(t_diff_list)
      
        if s_diff * t_diff < 0:
            dist = []
            for i in range(len(s_diff_list)):
                for j in range(len(t_diff_list)):
                    dist.append(abs(s_diff_list[i]-t_diff_list[j]) + min(abs(s_diff_list[i]), abs(t_diff_list[j])))
            print(min(dist))
            
        elif s_diff * t_diff > 0:
            print(max(abs(s_diff), abs(t_diff)))
        else:
            print(abs(s_diff+t_diff))

shrine_no, temple_no, q = map(int, input().split())
locate = []
start = []

for i in range(shrine_no+temple_no+q):
    tmp = int(input())
    if i < shrine_no+temple_no:
        locate.append(tmp)
    else:
        start.append(tmp)

for i in range(len(start)):
    calc(locate, start[i])

### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
loc = [int(input()) for i in range(Q)]
for i in range(len(loc)):
    x = loc[i]
    res = INF
    s_w, t_w = bisect.bisect_right(s,x), bisect.bisect_right(t,x)
    d1 = abs(s[s_w]-x) + abs(t[t_w]-s[s_w])
    d2 = abs(t[t_w]-x) + abs(s[s_w]-t[t_w])
    d3 = abs(s[s_w]-x) + abs(t[t_w-1]-s[s_w])
    d4 = abs(t[t_w-1]-x) + abs(t[t_w-1]-s[s_w])
    d5 = abs(s[s_w-1]-x) + abs(t[t_w]-s[s_w-1])
    d6 = abs(t[t_w]-x) + abs(s[s_w-1]-t[t_w])
    d7 = abs(s[s_w-1]-x) + abs(t[t_w-1]-s[s_w-1])
    d8 = abs(t[t_w-1]-x) + abs(s[s_w-1]-t[t_w-1])
    print(min(d1,d2,d3,d4,d5,d6,d7,d8))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(n):
  for j in range(n):
    if a[i] % a[j] == 0 and i != j:
      ans += 1
      break
  
print(n-ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
kmax = sorted(a)[-1]
c = [0]*(kmax+1)

for i in range(n):
  c[a[i]] -= 1
  for j in range(a[i],(kmax+1),a[i]):
    c[j] += 2

ans=c.count(1)
print(ans)
### BUGGY CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    total = (H - 2) * (W - 2)
    res = [0] * 10
    used = set()
    for a, b in AB:
        if (a, b) in used:
            continue
        que = deque([(a, b)])
        while que:
            h, w = que.popleft()
            used.add((h, w))
            cnt = 0
            flg = True
            for dh, dw in d:
                next_h, next_w = h + dh, w + dw
                if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                    flg = False
                else:
                    if (next_h, next_w) in AB:
                        cnt += 1
                    if (next_h, next_w) not in used:
                        used.add((next_h, next_w))
                        que.append((next_h, next_w))
            if flg:
                res[cnt] += 1
    t = total - sum(res)
    res[0] += t
    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    target = set()
    res = [0] * 10
    for h, w in AB:
        cnt = 0
        flg = True
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                flg = False
            if (next_h, next_w) in AB:
                cnt += 1
            else:
                target.add((next_h, next_w))
        if flg:
            res[cnt] += 1

    for h, w in target:
        cnt = 0
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                break
            if (next_h, next_w) in AB:
                cnt += 1
        else:
            res[cnt] += 1

    total = (H - 2) * (W - 2)
    res[0] = total - sum(res)
    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

from itertools import *
import sys

maxnum = 50000
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False
p = [ i for i in xrange(maxnum) if primes[i]]

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    if d % 2 == 1:
        try: p.index(d-2) ;print 1
        except: print 0; continue
    q = [ r for r in p if r < d]
    c = 0
    for j,k in combinations_with_replacement(q,2):
        if j+k==d: c += 1
    print c

### FIXED CODE ###

from itertools import *
import sys

maxnum = 50001
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

p = [ i for i in xrange(maxnum) if primes[i] ]
c = [0]*maxnum*2
for i,j in combinations_with_replacement(p,2):
    c[i+j] += 1

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    print c[d]
### BUGGY CODE ###

import numpy as np
N, K = map(int, input().split())
d = []
for _ in range(N):
    a, b= map(int, input().split())
    c = [a] * b
    d += c

print(sorted(d)[K-1])

### FIXED CODE ###

N, K = map(int, input().split())
num = [0]*(10**5+1)
for i in range(N):
    a, b= map(int, input().split())
    num[a] += b
for i in range(1, 10**5+1):
    if K <= num[i]:
        print(i)
        exit()
    K -= num[i]
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

ac = 1
for i in range(K):
    ac *= A[i]

for i in range(K, N):
    if A[i-K] < A[i]: print('Yes')
    else: print('No')



### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K, N):
    if A[i-K] < A[i]: print('Yes')
    else: print('No')
### BUGGY CODE ###

      
def binary_search(A,n):
    # sequence A, item n
    l=len(A)
    if l==0:
        return False
    elif A[l/2] > n:
        return binary_search(A[:l/2],n)
    elif A[l/2] == n:
        return True
    elif A[l/2]<n:
        return binary_search(A[(l/2)+1:],n)

n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())

C = 0
for k in range(len(T)):
    if binary_search(S,T[k]):
        C += 1
print C

### FIXED CODE ###

# coding: utf-8
# Here your code !
n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
C = 0

def binary_search(A,n):
    """no recursion version"""
    l = len(A)
    left = l/2
    right = l-1
    while A[left] != n:
        if left == right and A[left] != n:
            #print left,right,"if"
            return False
        elif A[left] > n: # n????????????????????´???
            right = left
            left = left/2
            #print left,right,"elif1"
        elif A[left] < n: # n????????????????????´???
            right = right
            left = (left + right-1)/2 + 1
            #print left,right,"elif2"
    else:
        return True

for item in T:
    if binary_search(S,item):
        C += 1
print C
### BUGGY CODE ###

n = int(input())
s = input()
c = 0
for i in range(n):
    for j in range(i, n):
        if s[i] == s[j]:
            continue
        for k in range(j, n):
            if s[i] == s[k] or s[j] == s[k]:
                continue
            elif (j + 1) - (i + 1) != (k + 1) - (j + 1):
                c += 1
print(c)

### FIXED CODE ###

n = int(input())
s = input()
r = set()
g = set()
b = set()
for i in range(n):
    if s[i] == "R":
        r.add(i)
    if s[i] == "G":
        g.add(i)
    if s[i] == "B":
        b.add(i)
a = len(r) * len(b) * len(g)
for i in r:
    for j in b:
        k = abs(i - j)
        if i + k in g:
            a -= 1
        if i - k in g:
            a -= 1
        if j + k in g:
            a -= 1
        if j - k in g:
            a -= 1
        if (i + j) / 2 in g:
            a -= 1
print(a)
### BUGGY CODE ###

from collections import deque


S = deque(list(input()))
Q = int(input())
queries = []
for _ in range(Q):
    query = input().split()
    if len(query) == 3:
        queries.append([int(x) for x in query[:2]] + [query[2]])
    else:
        if len(queries[-1]) == 1:
            queries.pop()
        else:
            queries.append([int(x) for x in query])

for query in queries:
    if len(query) == 3:
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
    else:
        S.reverse()
print(''.join(S))

### FIXED CODE ###

from collections import deque


S = deque(list(input()))
Q = int(input())
queries = []
for _ in range(Q):
    query = input().split()
    if len(query) == 3:
        queries.append([int(x) for x in query[:2]] + [query[2]])
    else:
        if len(queries[-1]) == 1:
            queries.pop()
        else:
            queries.append([int(x) for x in query])
p = True
count = 0
for query in queries:
    if len(query) == 3:
        if p:
            if query[1] == 1:
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == 1:
                S.append(query[2])
            else:
                S.appendleft(query[2])
    else:
        p = not p
        count += 1

if count % 2:
    S.reverse()
print(''.join(S))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

L = 30
ans = 0
for l in range(L):
    P = []
    g = 1<<l
    for b in B:
        P.append(b%(2*g))
    P.sort()
    count = 0
    for a in A:
        count += (bisect_left(P, (2*g-a)%(2*g)) - bisect_left(P, (g-a)%(2*g)))%N
    if count%2 == 1:
        ans += g
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


L = 30
ans = 0
for l in range(L):
    P = []
    g = 1<<l
    g2 = 1<<(1+l)
    B1 = []
    B2 = []
    for b in B:
        if b&g:
            B1.append(b)
        else:
            B2.append(b)
    B = B2 + B1

    A1 = []
    A2 = []
    for a in A:
        if a&g:
            A1.append(a)
        else:
            A2.append(a)
    A = A1 + A2

    count = 0
    ind1 = 0
    ind2 = 0
    ind3 = 0
    for a in A:
        while ind1 < N and B[ind1]%g2 + a%g2 < g:
            ind1 += 1
        while ind2 < N and B[ind2]%g2 + a%g2 < 2*g:
            ind2 += 1
        while ind3 < N and B[ind3]%g2 + a%g2 < 3*g:
            ind3 += 1
        count += ind2 - ind1 + N - ind3
    if count%2 == 1:
        ans += g
print(ans)
### BUGGY CODE ###

def main(N,A):
    B=[0]
    count = 0
    for i in range(len(A)):
        T = A[i] + B[i]
        for m in range(len(B)):
            if T - B[m] == 0:
                # print(i, m)
                # print(B[i],B[i-m])
                # print(T)
                # print("kore",B[i],B[i-m])
                count += 1
        B.append(T)

    #print(count)
    #print(B)
    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))
    if N == len(A):
        main(N,A)

### FIXED CODE ###

import collections

def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]

        B.append(T)
    c = collections.Counter(B)

    for i in range(len(c)):
        k, v = c.popitem()
        for z in range(v):
            count += z

    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC68 C

n,m = map(int,input().split())

ab = [list(map(int,input().split())) for _ in range(m)]
s = [ab[i][1] for i in range(m) if ab[i][0] == 1]
g = [ab[i][0] for i in range(m) if ab[i][1] == n]
f = 0
for i in s:
    if i in g:
        f = 1
        break
if f:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


### FIXED CODE ###

#!/usr/bin/env python3
#ABC68 C

n,m = map(int,input().split())

s = [0]*(200000+1)
g = [0]*(200000+1)
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        s[b] += 1
    if b == n:
        g[a] += 1
f = 0
for i in range(200000+1):
    if s[i] & g[i]:
        f = 1
        break
if f:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')