Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03241 (python)

Fixed submission:
n, m = map(int,input().split())
ps = [1]
nw = 1
mi = m//n
while nw**2 < m:
    if m%nw == 0:
        if mi >= nw:
            ps.append(nw)
        if mi >= m//nw:
            ps.append(m//nw)
    nw += 1
if nw**2 == m and nw <= mi:
    ps.append(nw)

print(max(ps))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
ps = [1]
nw = 1
mi = m//n
while nw**2 < m:
    if m%nw == 0:
        if mi >= nw:
            ps.append(nw)
        if mi >= m//nw:
            ps.append(m//nw)
    nw += 1
if nw**2 == m and nm <= mi:
    ps.append(nw)

print(max(ps))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
ps = []
nw = 1
mi = m//n
while nw**2 < m:
    if m%nw == 0:
        if mi >= nw:
            ps.append(nw)
        if mi >= m//nw:
            ps.append(m//nw)
    nw += 1
if nw**2 == m and nm <= mi:
    ps.append(nw)

print(max(ps))
Problem p03394 (python)

Fixed submission:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
#    n = 20000
    if n == 3:
        print("2 3 25")
        exit()
    elif n == 4:
        print("2 5 20 63")
        exit()
    tn = (n//8)*8
    sm = 0
    nm = 0
    ans = []
    la = 0
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == tn:
            if ans:
                la = ans[-1]
            break

    if n%8 == 0:
        pass
    elif n%8 == 1:
        ans.append(la+6)
    elif n%8 == 2:
        ans.append(la+2)
        ans.append(la+4)
    elif n%8 == 3:
        ans.append(la+2)
        ans.append(la+4)
        ans.append(la+6)
    elif n%8 == 4:
        ans.append(la+2)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+12)
    elif n%8 == 5:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+6)
        ans.append(la+9)
    elif n%8 == 6:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+9)
        ans.append(la+8)
        ans.append(la+10)
    elif n%8 == 7:
        ans.append(la+2)
        ans.append(la+3)
        ans.append(la+4)
        ans.append(la+9)
        ans.append(la+8)
        ans.append(la+10)
        ans.append(la+12)


    print(" ".join(map(str,ans)))


    return None

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
#    n = 20000
    tn = (n//4)*4
    sm = 0
    nm = 0
    ans = []
    for i in range(1,30001):
        if i%2 == 0 or i%3 == 0:
            ans.append(i)
            sm += i
            nm += 1
        if nm == tn:
            break

    if n%4 == 0:
        pass
    elif n%4 == 1:
        ans.append(ans[-1]+6)
    elif n%4 == 2:
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)
    else:
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)
        ans.append(ans[-1]+2)

    print(" ".join(map(str,ans)))


    return None

if __name__ == '__main__':
    main()
Problem p03403 (python)

Fixed submission:
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    a = [0]+list(map(int,input().split()))+[0]
    lc = [0 for i in range(n)]
    sum = abs(a[0]-a[1])
    for i in range(n):
        lc[i] = abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])-abs(a[i]-a[i+2])
        sum += abs(a[i+1]-a[i+2])
    for i in range(n):
        print(sum-lc[i])



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    a = [0]+list(map(int,input().split()))+[0]
    lc = [0 for i in range(n)]
    sum = abs(a[0]-a[1])
    for i in range(n):
        lc[i] = abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])-abs(a[i]-a[i+2])
        sum += abs(a[i+1]-a[i+2])
    for i in range(n):
        print(sum-lc[i])



if __name__ == '__main__':
    main()
Problem p03421 (python)

Fixed submission:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a*b < n or a+b-1 > n:
        print(-1)
        exit()
    ans = [str(b-i) for i in range(b)]
    si = n-a+2
    ue = n+1
    i = 0
    while True:
        if si <= b or a == 1:
            break
        ans[i] += " "+" ".join(map(str,range(si,ue)))
        ue = si
        si -= a-1
        i += 1
    if i < b and b+1 < ue:
        ans[i] += " "+" ".join(map(str,range(b+1,ue)))
    print(" ".join(ans))
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a*b < n or a+b-1 > n:
        print(-1)
        exit()
    ans = [str(b-i) for i in range(b)]
    si = n-a+2
    ue = n+1
    i = 0
    while True:
        if si <= b:
            break
        ans[i] += " "+" ".join(map(str,range(si,ue)))
        ue = si
        si -= a-1
        i += 1
    if i < b and b+1 < ue-1:
        ans[i] += " "+" ".join(map(str,range(b+1,ue)))
    print(" ".join(ans))
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a*b < n or a+b-1 > n:
        print(-1)
        exit()
    ans = [str(b-i)+" " for i in range(b)]
    si = n-a+2
    ue = n+1
    i = 0
    while True:
        if si <= b:
            break
        ans[i] += " ".join(map(str,range(si,ue)))
        ue = si
        si -= a-1
        i += 1
    if i < b:
        ans[i] += " ".join(map(str,range(b+1,ue)))
    print(" ".join(ans))
    return

if __name__ == '__main__':
    main()
Problem p03612 (python)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
ans = 0

flag = False
for i in range(n):
    if flag:
        flag = False
        continue
    if p[i] == i+1:
        if i < n-1 and p[i+1] == i+2:
            flag = True
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
ans = 0

flag = False
for i in range(n):
    if flag:
        flag = False
        continue
    if p[i] == i+1:
        if i < n+1 and p[i+1] == i+2:
            flag = True
        ans += 1

print(ans)
Problem p03837 (python)

Fixed submission:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    cos = []
    row = []
    col = []
    for _ in range(m):
        a,b,c = map(int,ipt().split())
        row.append(a-1)
        col.append(b-1)
        cos.append(c)
    csr = csr_matrix((cos,(row,col)),shape=(n,n))
    d = dijkstra(csr,directed=False)
    ans = 0
    for i in range(m):
        rwi = row[i]
        cli = col[i]
        csi = cos[i]
        dri = d[rwi]
        dci = d[cli]
        for j in range(n):
            if dri[j] + csi == dci[j]:
                break
            if j == n-1:
                ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    cos = []
    row = []
    col = []
    for _ in range(m):
        a,b,c = map(int,ipt().split())
        row.append(a-1)
        col.append(b-1)
        cos.append(c)
        cos.append(c)
    csr = csr_matrix((cos,(row,col)),shape=(n,n))
    d = dijkstra(csr,directed=False)
    ans = 0
    for i in range(m):
        csr = csr_matrix((cos[:i:]+cos[i+1::],(row[:i:]+row[i+1::],col[:i:]+col[i+1::])),shape=(n,n))
        di = dijkstra(csr)
        if (di == d).all():
            ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()
Problem p03946 (python)

Fixed submission:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,t = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    bs = []
    mi = a[0]
    for i in a[1::]:
        if mi < i:
            bs.append(i-mi)
        else:
            mi = i
    ma = max(bs)
    cnt = 0
    for i in bs:
        if i == ma:
            cnt += 1

    print(cnt)
    return None

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,t = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    d = []
    u = []
    pv = 1000000
    for i in range(n-1):
        if pv > a[i] < a[i+1]:
            d.append(a[i])
        elif pv < a[i] > a[i+1]:
            u.append(a[i])
        if a[i] != a[i+1]:
            pv = a[i]

    if pv < a[-1]:
        u.append(a[-1])

    ds = []
    if len(u) != len(d):
        print(asdasd)
    for ui,di in zip(u,d):
        ds.append(ui-di)
    dma = max(ds)
    cnt = 0
    for i in ds:
        if dma == i:
            cnt += 1
    print(cnt)
    return None

if __name__ == '__main__':
    main()
Problem p02632 (python)

Fixed submission:
def resolve():
    MOD = 10 ** 9 + 7
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv
 
    # 二項係数計算
    def Combination(n, k, MOD=10 ** 9 + 7):
        # fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
        return ret
 
    K = int(input())
    S = input()
    N = len(S)
 
    fac, finv = COMinit(N + K, MOD)
    v = 1
    ans = 0
    for i in range(K + 1):
        ans += Combination(N + K, i) * v
        ans %= MOD
        v *= 25
        v %= MOD
    print(ans)
    
if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    MOD = 10 ** 9 + 7
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv

    # 二項係数計算
    def Combination(n, k, MOD=10 ** 9 + 7):
        # fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
        return ret

    K = int(input())
    S = input()
    N = len(S)

    fac, finv = COMinit(N + K, MOD)
    v = 1
    ans = 0
    for i in range(K + 1):
        ans += Combination(N + K, i) * v
        ans %= MOD
        v *= 25
        v %= MOD
    print(ans)

if __name__ == "__main__":
    
def resolve():
    MOD = 10 ** 9 + 7
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv

    # 二項係数計算
    def Combination(n, k, MOD=10 ** 9 + 7):
        # fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
        return ret

    K = int(input())
    S = input()
    N = len(S)

    fac, finv = COMinit(N + K, MOD)
    v = 1
    ans = 0
    for i in range(K + 1):
        ans += Combination(N + K, i) * v
        ans %= MOD
        v *= 25
        v %= MOD
    print(ans)

if __name__ == "__main__":
    resolve()
Problem p02641 (python)

Fixed submission:

def resolve():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return
    A = set(map(int, input().split()))
    dic = {}
    for i in range(-10, 110):
        if i not in A:
            dic[i] = abs(X-i)

    sorted_A = sorted(dic.items(), key=lambda x:(x[1], x[0]))
    print(sorted_A[0][0])

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return
    A = set(map(int, input().split()))
    dic = {}
    for i in range(1, 101):
        if i not in A:
            dic[i] = abs(X-i)

    sorted_A = sorted(dic.items(), key=lambda x:x[1])
    print(sorted_A[0][0])

if __name__ == "__main__":
    resolve()
Problem p02692 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
 

def resolve():
    N, A, B, C = map(int, inp().split())
    S = [inpS() for _ in range(N)]
 
    ans = []
    def dfs(now, a, b, c):
        if now == N:
            return True
        if S[now] == "AB":
            if a == 0 and b == 0:
                return False
            if 0 < a and dfs(now+1, a-1, b+1, c):
                ans.append("B")
                return True
            if 0 < b and dfs(now+1, a+1, b-1, c):
                ans.append("A")
                return True
            return False
        if S[now] == "AC":
            if a == 0 and c == 0:
                return False
            if 0 < a and dfs(now+1, a-1, b, c+1):
                ans.append("C")
                return True
            if 0 < c and dfs(now+1, a+1, b, c-1):
                ans.append("A")
                return True
            return False
        if S[now] == "BC":
            if c == 0 and b == 0:
                return False
            if 0 < b and dfs(now+1, a, b-1, c+1):
                ans.append("C")
                return True
            if 0 < c and dfs(now+1, a, b+1, c-1):
                ans.append("B")
                return True
            return False
 
    dfs(0, A, B, C)
    if len(ans) == 0:
        print("No")
        return
    else:
        print("Yes")
        [print(a) for a in ans[::-1]]
 
 
if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    N, A, B, C = map(int, input().split())
    S = [input() for _ in range(N)]

    ans = []
    def dfs(now, a, b, c):
        if now == N:
            return True
        if S[now] == "AB":
            if a == 0 and b == 0:
                return False
            if 0 < a and dfs(now+1, a-1, b+1, c):
                ans.append("B")
                return True
            if 0 < b and dfs(now+1, a+1, b-1, c):
                ans.append("A")
                return True
            return False
        if S[now] == "AC":
            if a == 0 and c == 0:
                return False
            if 0 < a and dfs(now+1, a-1, b, c+1):
                ans.append("C")
                return True
            if 0 < c and dfs(now+1, a+1, b, c-1):
                ans.append("A")
                return True
            return False
        if S[now] == "BC":
            if c == 0 and b == 0:
                return False
            if 0 < b and dfs(now+1, a, b-1, c+1):
                ans.append("C")
                return True
            if 0 < c and dfs(now+1, a, b+1, c-1):
                ans.append("B")
                return True
            return False

    dfs(0, A, B, C)
    if len(ans) == 0:
        print("No")
        return
    else:
        print("Yes")
        [print(a) for a in ans[::-1]]


if __name__ == "__main__":
    resolve()
Problem p02696 (python)

Fixed submission:

def resolve():
    def f(x):
        res = (A*x)//B - A*(x//B)
        return res

    A, B, N = map(int, input().split())
    x = min(B-1, N)
    print(f(x))

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    def f(x):
        res = (A*x)//B - A*(x//B)
        return res

    A, B, N = map(int, input().split())
    x = min(B-1, N)
    print(f(x))

if __name__ == "__main__":
    resolve():
Problem p02758 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from collections import Counter
class HeapSet:
    def __init__(self):
        self.minQue = []
        self.maxQue = []
        self.counter = Counter()

    def insert(self, x):
        heappush(self.minQue, x)
        #heappush(self.maxQue, -x)
        self.counter[x] += 1

    def erase(self, x):
        self.counter[x] -= 1

    def max(self):
        while self.maxQue and self.counter[-self.maxQue[0]] == 0:
            heappop(self.maxQue)
        return -self.maxQue[0] if self.maxQue else None

    def min(self):
        while self.minQue and self.counter[self.minQue[0]] == 0:
            heappop(self.minQue)
        return self.minQue[0] if self.minQue else None

MOD = 998244353
def resolve():
    def dfs(v):
        res = 1
        for to in to_edge[v]:
            res *= dfs(to)
            res %= MOD
        return res +1

    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort()
    st = HeapSet()
    to_edge = [[] for _ in range(N)]
    # treeを作成
    for i in range(N-1, -1, -1):
        x = AB[i][0] # 初期位置
        d = AB[i][1] # 移動距離

        while st.min() and st.min()[0] < x + d:
            to_edge[i].append(st.min()[1])
            st.erase(st.min())
        st.insert((x,i)) # 初期位置、頂点番号

    ans = 1
    for (x, v) in st.minQue:
        ans *= dfs(v)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):

from heapq import heappush, heappop
from collections import Counter
class HeapSet:
    def __init__(self):
        self.minQue = []
        self.maxQue = []
        self.counter = Counter()

    def insert(self, x):
        heappush(self.minQue, x)
        #heappush(self.maxQue, -x)
        self.counter[x] += 1

    def erase(self, x):
        self.counter[x] -= 1

    def max(self):
        while self.maxQue and self.counter[-self.maxQue[0]] == 0:
            heappop(self.maxQue)
        return -self.maxQue[0] if self.maxQue else None

    def min(self):
        while self.minQue and self.counter[self.minQue[0]] == 0:
            heappop(self.minQue)
        return self.minQue[0] if self.minQue else None

MOD = 998244353
def resolve():
    def dfs(v):
        res = 1
        for to in to_edge[v]:
            res *= dfs(to)
            res %= MOD
        return res +1

    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort()
    st = HeapSet()
    to_edge = [[] for _ in range(N)]
    # treeを作成
    for i in range(N-1, -1, -1):
        x = AB[i][0] # 初期位置
        d = AB[i][1] # 移動距離

        while st.min() and st.min()[0] < x + d:
            to_edge[i].append(st.min()[1])
            st.erase(st.min())
        st.insert((x,i)) # 初期位置、頂点番号

    ans = 1
    for (x, v) in st.minQue:
        ans *= dfs(v)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    resolve()
Problem p02761 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

def check(n):
  x = str(n)
  if len(x) != N:
    return False
  for s, c in SC:
    if x[s-1] != str(c):
      return False
  return True
  
N, M = map(int, inp().split())
SC = [tuple(map(int, inp().split())) for _ in range(M)]

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

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N, M = map(int, inp().split())
SC = [tuple(map(int, inp().split())) for _ in range(M)]
SC = sorted(SC, key=lambda x:(x[0],-(x[1])))
max_N = (SC[0][1]+1)*(10**(N-1))
min_N = 10**(N-1)

ans = 1005
for i in range(max_N, min_N, -1):
  x = str(i)
  cnt = 0
  for s, c in SC:
    if int(x[s-1]) == c:
      cnt += 1
  if cnt == M:
    ans = min(ans, i)
print(ans if ans < 1005 else -1)