Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
    p,s = input().split()
    num = p - 1
    if num not in ac_cnt:
        if s == "AC":
            ac_cnt.add(num)
            wa_cnt += penalty[num]
        else:
            penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)
    

Fixed submission:
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
    p,s = input().split()
    num = int(p) - 1
    if num not in ac_cnt:
        if s == "AC":
            ac_cnt.add(num)
            wa_cnt += penalty[num]
        else:
            penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

ans_ac = set()
wa_cnt = 0
wa_sled = [i for i in range(1,n+1)]


for i in range(m):
  p,s = input().split()
  if s == "AC":
    ans_ac.add(p)
    wa_sled.remove(int(p))
    if len(wa_sled) == 0:
      break
      
  if s == 'WA' and p not in wa_sled:
    wa_cnt += 1
    
print(len(ans_ac),wa_cnt)

Fixed submission:
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
    p,s = input().split()
    num = int(p) - 1
    if num not in ac_cnt:
        if s == "AC":
            ac_cnt.add(num)
            wa_cnt += penalty[num]
        else:
            penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in range(n):
  if ans in a[i:n]:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

Fixed submission:
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
    p,s = input().split()
    num = int(p) - 1
    if num not in ac_cnt:
        if s == "AC":
            ac_cnt.add(num)
            wa_cnt += penalty[num]
        else:
            penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in range(n):
  if ans in a[i:n]:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in a:
  if i == ans:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in range(n):
  if ans in a[i:n]:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in a:
  if i == ans:
    ans += 1
    continue
  cnt += 1
  
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  if ans != 0:
    print('No')
    exit()
  if i % 2 == 0:
    if s[i] == 'R':
      ans += 1
  else:
    if s[i] == 'L':
      ans += 1
print('Yes')
    

Fixed submission:
s = input()
ans = 0
for i in range(1,len(s)+1):
    if i%2 == 1:
        if s[i-1] == "R" or s[i-1] == "U" or s[i-1] == "D":
            ans += 1
        else:
            print('No')
            exit()
    elif i%2 == 0:
        if s[i-1] == 'L' or s[i-1] == "U" or s[i-1] == "D":
            ans += 1
        else:
            print('No')
            exit()
if ans == len(s):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
q = a-b
ans = c - ans

if ans < 0:
  ans = 0
  
print(ans)

Fixed submission:
a,b,c = map(int,input().split())
q = a-b
ans = c-q

if ans < 0:
  ans = 0
  
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

for i in range(1,n-1):
    if h[i-1] <= h[i] <= h[i+1]:
        continue
    else:
        if h[i]>h[i+1]:
            h[i] -= 1
            if h[i]< h[i-1]:
                print('No')
                exit()

for i in range(1,n-1):
    if not h[i-1]=<h[i] <= h[i+1]:
        print('No')
        exit()

print('Yes')

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
m = h[0]
for i in range(1,n):
    m = max(m,h[i])
    if h[i] >= m-1:
        continue
    print('No')
    exit()


print('Yes')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
q = set(sorted(a))

for i in range(n):
  if a[i] != q[-1]:
    print(q[-1])
  else:
    print(q[-2])

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
q = sorted(a)

for i in range(n):
  if a[i] != q[-1]:
    print(q[-1])
  else:
    print(q[-2])
Buggy python submission (verdict: Runtime Error):
s = input()
for i in s:
  if s.counter(i) != 2:
    print('No')
    exit()
print('Yes')

Fixed submission:
s = input()
for i in s:
  if s.count(i) != 2:
    print('No')
    exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
n = int(input())
m = [i for i in range(1,n+1)]
p = list(map(int,input().split()))
cnt = 0
for i in m:
    if p[i-1] == i:
        p[i-1] = p[i]
        p[i] = i
        cnt += 1
    
print(cnt)

Fixed submission:
n = int(input())
m = [i for i in range(1,n)]
p = list(map(int,input().split()))
cnt = 0
for i in m:
    if p[i-1] == i:
        p[i-1] = p[i]
        p[i] = i
        cnt += 1

if p[-1] == n:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input())

s = (n - 1)*(m - 1)
print(s)

Fixed submission:
n,m = map(int,input().split())

s = (n - 1)*(m - 1)
print(s)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
for i in range(h):
  q = input()
  print(q)
  print(q)

Fixed submission:
n,m = map(int,input().split())
for i in range(n):
  q = input()
  print(q)
  print(q)
Buggy python submission (verdict: Runtime Error):
a,b,c = input().split()
print(a[0],upper(b[0]),c[0])


Fixed submission:
a,b,c = input().split()
b.upper()
print(a[0]+b[0]+c[0])

Buggy python submission (verdict: Runtime Error):
a,b,c = input().split()
print(upper(a[0],b[0],c[0]))


Fixed submission:
a,b,c = input().split()
b.upper()
print(a[0]+b[0]+c[0])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
s = range(a,b+1)
q = 0
for i in s:
  if i%x == 0:
    q += 1
    
print(q)

Fixed submission:
def readinput():
    a,b,x=list(map(int,input().split()))
    return a,b,x
 
def main(a,b,x):
    ans = b//x - (a-1)//x
    return ans
 
if __name__=='__main__':
    a,b,x=readinput()
    ans=main(a,b,x)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
s = range(a,b+1)
q = 0
for i in s:
  if i%x == 0:
    q += 1
    
print(q)

Fixed submission:
def readinput():
    a,b,x=list(map(int,input().split()))
    return a,b,x
 
def main(a,b,x):
    ans = b//x - (a-1)//x
    return ans
 
if __name__=='__main__':
    a,b,x=readinput()
    ans=main(a,b,x)
    print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,x = map(int,input().split())
a = range(a,b+1)
q = 0
for i in a:
  if a%i == 0:
    q += 1
    
print(q)

Fixed submission:
def readinput():
    a,b,x=list(map(int,input().split()))
    return a,b,x
 
def main(a,b,x):
    ans = b//x - (a-1)//x
    return ans
 
if __name__=='__main__':
    a,b,x=readinput()
    ans=main(a,b,x)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
ans = 1
if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
a = readints()
ans = [0]*(N+1)
for i in range(len(a)):
    for j in range(1, N+1):
        if a[i] == j:
            ans[j] += 1
for i in range(len(ans)-1):
    print(ans[i+1])


Fixed submission:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
a = readints()
ans = [0]*(N+1)
for i in range(len(a)):
    ans[(a[i])] += 1
for i in range(len(ans)-1):
    print(ans[i+1])
Buggy python submission (verdict: Runtime Error):
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = int(input())
S = input()
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i+1)
    if S[i] == 'G':
        g.append(i+1)
    if S[i] == 'B':
        b.append(i+1)
c = [None]*100
for i in range(100):
    c[i] = [None]*100
cnt = 0
for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            c[i][0] = r[i]
            c[i][1] = g[j]
            c[i][2] = b[k]

            if c[i][1]-c[i][0] != c[i][2]-c[i][1]:
                #print(c[i][0], c[i][1], c[i][2], 'Yes')
                cnt += 1

print(cnt)


Fixed submission:
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = input()
if '7' in N:
    print("Yes")
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = int(input())
S = input()
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i+1)
    if S[i] == 'G':
        g.append(i+1)
    if S[i] == 'B':
        b.append(i+1)
print(r)
print(g)
print(b)
c = [None]*100
for i in range(100):
    c[i] = [None]*100
cnt = 0
for i in range(len(r)):
    for j in range(len(g)):
        for k in range(len(b)):
            c[i][0] = r[i]
            c[i][1] = g[j]
            c[i][2] = b[k]

            if c[i][1]-c[i][0] != c[i][2]-c[i][1]:
                #print(c[i][0], c[i][1], c[i][2], 'Yes')
                cnt += 1

print(cnt)


Fixed submission:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N = int(input())
S = input()
L = [None]*3
L[0] = []
L[1] = []
L[2] = []
for i in range(N):
    if S[i] == 'R':
        L[0].append(i)
    if S[i] == 'G':
        L[1].append(i)
    if S[i] == 'B':
        L[2].append(i)
cnt = 0
wa = [None]*3
for i in range(3):
    wa[i] = [0]*(N+1)
for i in range(3):
    for j in range(N):
        if S[j] == "RGB"[i]:
            wa[i][j+1] = 1
for i in range(3):
    for j in range(N):
        wa[i][j+1] = wa[i][j]+wa[i][j+1]
for x in itertools.permutations([0, 1, 2]):
    r = L[x[0]]
    g = L[x[1]]
    b = L[x[2]]
    for i in range(len(r)):
        for j in range(len(g)):
            if r[i] < g[j]:
                cnt += wa[x[2]][N]-wa[x[2]][g[j]+1]
                if len(S) > (g[j]-r[i])+g[j] and S[(g[j]-r[i])+g[j]] == "RGB"[x[2]]:
                    cnt -= 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


n, m = map(int, input().split())
#print(n, m)
if n == 1:
    print(0)
    exit()
a = nCr(n, 2)
print(a+m)


Fixed submission:
import math
import string
import collections
from collections import Counter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


n, m = map(int, input().split())
print(n*(n-1)//2+m*(m-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import string
import collections
from collections import Counter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


n = int(input())
a = readints()
# print(a)
aa = a[1:]
so_aa = sorted(aa)
c = Counter(so_aa)
d = c.most_common()
# print(d)
sum = 0
for i in range(len(d)):
    if d[0+i][1] != 1:
        sum += nCr(d[0+i][1], 2)
print(sum)
for j in range(1, n):
    aaa = a[:j]+a[j+1:]
    so_aaa = sorted(aaa)
    cc = Counter(so_aaa)
    dd = cc.most_common()
    # print(dd)
    sumsum = 0
    for k in range(len(dd)):
        # sumsum = 0
        if dd[0+k][1] != 1:
            sumsum += nCr(dd[0+k][1], 2)
    print(sumsum)


Fixed submission:
import math
import string
import collections
from collections import Counter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()
# print(a)
c = Counter(a)  # リストの各要素の出現回数をカウント
# print(c)
cnt = 0
# print(c.values())
for i in c.values():
    # 各要素の値に対してforループ処理
    cnt += i*(i-1)//2
for aa in a:
    x = c[aa]
    # print(x)
    ans = (cnt-x*(x-1)//2+(x-1)*(x-2)//2)
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
# print(a)
# print(b)
# print(c)
n = int(input())
d = [int(input()) for i in range(n)]
# print(d)

if (a[0]in d) and (a[1]in d) and(a[2]in d):
    print("Yes")
    exit()
if (b[0]in d)and(b[1]in d)and(b[2]in d):
    print("Yes")
    exit()
if (c[0]in d)and(c[1]in d)and(c[2]in d):
    print("Yes")
    exit()
if (a[2]in d)and(b[1]in d)and(c[0]in d):
    print("Yes")
    exit()
if (a[0]in d)and(b[1]in d)and(c[2]in d):
    print("Yes")
    exit()
if (a[0]in d)and(b[0]in d)and(c[0]in d):
    print("Yes")
    exit()
if (a[2]in d)and(b[2]in d)and(c[2]in d):
    print("Yes")
    exit()
else:
    print("No")


Fixed submission:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n = int(input())
if n % 2 == 0:
    print((n//2))
else:
    print((n//2)+1)
Buggy python submission (verdict: Runtime Error):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, m = map(int, input().split())
sc = [input().split() for i in range(m)]
# print(sc)
# print(len(sc))
if len(sc) == 1:
    print(-1)
    exit()

for i in range(m):
    if (sc[0][0] == sc[i][0])and(sc[0][1] != sc[i][1]):
        print(-1)
        exit()

#print(sorted(set(list(map(tuple, sc)))))
x = sorted(set(list(map(tuple, sc))))
# print(len(x))
# print(x[0][0])
for i in range(len(x)):
    if int(x[i][0]) == 1:
        h = 100*int(x[i][1])
        print(h)
    elif int(x[i][0]) == 2:
        i = 10*int(x[i][1])
        print(i)
    elif int(x[i][0]) == 3:
        j = 1*int(x[i][1])
        print(j)
print(h+i+j-1)


Fixed submission:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


N, M = map(int, input().split())
cs = [None]*N
for i in range(M):
    s, c = map(int, input().split())
    #print(s, c)
    if cs[(s-1)] == None:
        cs[(s-1)] = c
    elif cs[s-1] != c:
        print(-1)
        exit()


def check(x):
    s = str(x)
    if not(len(s) == N):
        return False
    for i in range(N):
        if not(cs[i] == None or cs[i] == int(s[i])):
            return False
    return True


for i in range(10000):
    if check(i):
        print(i)
        exit()
print(-1)

Buggy python submission (verdict: Runtime Error):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, m = map(int, input().split())
sc = [input().split() for i in range(m)]
# print(sc)
# print(len(sc))
if len(sc) == 1:
    print(-1)
    exit()

for i in range(m):
    if (sc[0][0] == sc[i][0])and(sc[0][1] != sc[i][1]):
        print(-1)
        exit()

#print(sorted(set(list(map(tuple, sc)))))
x = sorted(set(list(map(tuple, sc))))
# print(len(x))
# print(x[0][0])
for i in range(len(x)):
    if int(x[i][0]) == 1:
        h = 100*int(x[i][1])
        # print(h)
    elif int(x[i][0]) == 2:
        i = 10*int(x[i][1])
        # print(i)
    elif int(x[i][0]) == 3:
        j = 1*int(x[i][1])
        # print(j)
print(h+i+j)


Fixed submission:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


N, M = map(int, input().split())
cs = [None]*N
for i in range(M):
    s, c = map(int, input().split())
    #print(s, c)
    if cs[(s-1)] == None:
        cs[(s-1)] = c
    elif cs[s-1] != c:
        print(-1)
        exit()


def check(x):
    s = str(x)
    if not(len(s) == N):
        return False
    for i in range(N):
        if not(cs[i] == None or cs[i] == int(s[i])):
            return False
    return True


for i in range(10000):
    if check(i):
        print(i)
        exit()
print(-1)