Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
num = [0] * m
for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] != 0 and num[s-1] != c:
        print(-1)
        exit()
    num[s-1] = c

if 1 < n and num[0] == 0:
    print(-1)
    exit()

for i in range(1000):
    ok = True
    string = str(i)
    if len(string) == n:
        for j in range(n):
            if len(string) <= j or len(num) <= j:
                continue
            if num[j] == 0:
                continue
            elif string[j] != str(num[j]):
                ok = False
                break
        if ok:
            print(i)
            exit()
print(-1)

Fixed submission:
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))

# 条件の整理
cnt = [0]*4
for i in range(m):
    cnt[sc[i][0]] += 1
    # 最上位桁が0
    # if sc[i][0] == 1 and sc[i][0] == 0 and n > 1:
    #     print(-1)
    #     exit()
    # 同じ桁に違う数字指定
    if cnt[sc[i][0]] > 1:
        
        val = []
        
        for j in range(m):
            if sc[j][0] == sc[i][0]:
                val.append(sc[j][1])
        
        if len(list(set(val))) > 1:
            print(-1)
            exit()


# 全探索
ans = []
for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            digit = sc[j][0]
            val = sc[j][1]
            if int(str(i)[digit-1]) != val:
                flg = False
                break
        if flg == True:
            ans.append(i)

if len(ans) == 0:
    print(-1)
    exit()
print(min(ans))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
num = [0] * m
for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] != 0 and num[s-1] != c:
        print(-1)
        exit()
    num[s-1] = c

if 1 < n and num[0] == 0:
    print(-1)
    exit()

for i in range(1000):
    ok = True
    string = str(i)
    if len(string) == n:
        for j in range(n):
            if num[j] == 0:
                continue
            elif string[j] != str(num[j]):
                ok = False
                break
        if ok:
            print(i)
            exit()
print(-1)

Fixed submission:
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))

# 条件の整理
cnt = [0]*4
for i in range(m):
    cnt[sc[i][0]] += 1
    # 最上位桁が0
    # if sc[i][0] == 1 and sc[i][0] == 0 and n > 1:
    #     print(-1)
    #     exit()
    # 同じ桁に違う数字指定
    if cnt[sc[i][0]] > 1:
        
        val = []
        
        for j in range(m):
            if sc[j][0] == sc[i][0]:
                val.append(sc[j][1])
        
        if len(list(set(val))) > 1:
            print(-1)
            exit()


# 全探索
ans = []
for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            digit = sc[j][0]
            val = sc[j][1]
            if int(str(i)[digit-1]) != val:
                flg = False
                break
        if flg == True:
            ans.append(i)

if len(ans) == 0:
    print(-1)
    exit()
print(min(ans))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
num = [0] * m
for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] != 0 and num[s-1] != c:
        print(-1)
        exit()
    num[s-1] = c

if 1 < n and num[0] == 0:
    print(-1)
    exit()

for i in range(1000):
    ok = True
    string = str(i)
    if len(string) == n:
        for j in range(m):
            if num[j] == 0:
                continue
            elif string[j] != str(num[j]):
                ok = False
                # print(i)
                # print(j)
                break
        if ok:
            print(i)
            exit()
print(-1)

Fixed submission:
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))

# 条件の整理
cnt = [0]*4
for i in range(m):
    cnt[sc[i][0]] += 1
    # 最上位桁が0
    # if sc[i][0] == 1 and sc[i][0] == 0 and n > 1:
    #     print(-1)
    #     exit()
    # 同じ桁に違う数字指定
    if cnt[sc[i][0]] > 1:
        
        val = []
        
        for j in range(m):
            if sc[j][0] == sc[i][0]:
                val.append(sc[j][1])
        
        if len(list(set(val))) > 1:
            print(-1)
            exit()


# 全探索
ans = []
for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            digit = sc[j][0]
            val = sc[j][1]
            if int(str(i)[digit-1]) != val:
                flg = False
                break
        if flg == True:
            ans.append(i)

if len(ans) == 0:
    print(-1)
    exit()
print(min(ans))