peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
input = sys.stdin.readline

n, m = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(m)]

ans = -1

if n == 1:
    bottom = 0
else:
    bottom = 10 ** (n-1)
top = 10 ** n

for a in range(bottom, top):
    a = str(a)
    flag = True
    for v in sc:
        s = v[0] - 1
        c = str(v[1])
        if a[s] != c:
            flag = False
            break
    if flag:
        ans = a
        break

print(ans)
n,m = list(map(int, input().split()))
l=[list(map(int, input().split())) for _ in range(m)]
ans=[]
if n==1:
    ans.append('0')
ans+=[str(i) for i in range(10**(n-1),10**n)]

for s,c in l:
    ans = [k for k in ans if k[s-1]==str(c)]

if ans:
    print(ans[0])
else:
    print(-1)
"""
C
"""
import sys
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]

for i in range(10**N):
    if len(str(i))<N:
        continue
    lst=list(str(i))
    for s,c in sc:
        if int(lst[s-1])==c:
            continue
        else:
            break
    else:
        print(i)
        sys.exit()
print(-1)
import sys
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
 
for i in range(10**N):
    if len(str(i))<N:
        continue
    lst=list(str(i))
    for s,c in sc:
        if int(lst[s-1])==c:
            continue
        else:
            break
    else:
        print(i)
        sys.exit()
print(-1)
# -*- coding: utf-8 -*-
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append([int(i) for i in input().split()])

for i in range(0, 1000):
    i = str(i)
    if len(i) != n:
        continue
    flag = True
    for j in range(m):
        #print(i, i[sc[j][0] - 1], sc[j][1])
        if i[sc[j][0] - 1] != str(sc[j][1]):
            flag = False
    if flag:
        print(i)
        exit()
print(-1)
N, M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]

for i in range(1000):
    n = str(i)
    if len(n) == N:
        if all( n[s-1] == str(c) for s,c in A):
            print(i)
            break
else:
    print(-1)
n, m = map(int, input().split())
num = [-1 for _ in range(n + 1)]
for _ in range(m):
    s, c = map(int, input().split())
    if num[s] == -1 or num[s] == c:
        num[s] = c
    else:
        print('-1')
        exit()
if num[1] == -1 and n > 1:
    num [1] = 1
ans = ''
for i in num:
    if i == -1:
        ans += '0'
    else:
        ans += str(i)
print(int(ans) if len(str(int(ans))) == n else '-1')
n,m = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(m)]
for i in range(10**n):
    a = str(i)
    if len(a)!=n: continue
    for s,c in x:
        if a[s-1]!=str(c): break
    else:
        print(i)
        exit()
print(-1)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
  i2=str(i)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      exit()
print(-1)
n, m = list(map(int, input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(0, 10**n):
  str_i = str(i)
  if len(str_i) != n: continue

  chk = True
  for s, c in sc:
    chk &= str_i[s-1] == str(c)
  if chk:
    print(i)
    exit()

print(-1)
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
               #sc = [[1, 7], [3, 2], [1, 7]]
tmp = []
if n == 1:
    tmp.append(0)
for i in range(10**(n-1), 10**n):
    tmp.append(i)
 
ans = -1
for i in tmp:
    l = list(map(int, list(str(i))))
    if all(l[s-1] == c for s,c in sc):   #上の例で考えるとsは1、cは7が格納される
        ans = i
        break
print(ans)
N, M = map(int, input().split())
A = [{i for i in range(0, 10)} for _ in range(N)]
if N > 1:
    A[0].discard(0)
T = True
for _ in range(M):
    s, c = map(int, input().split())
    A[s-1] = A[s-1] & set([c])
    if len(A[s-1]) == 0:
        T = False
if T:
    X = ''
    for i in range(N):
        X += str(min(A[i]))
    print(X)
else:
    print(-1)
N, M = map(int, input().split())
ans = [0 for _ in range(N)]
if N == 1:
	ans[0] = 0
else:
	ans[0] = 1
f = 1
flg = [-1 for _ in range(M + 1000)]

for _ in range(M):
	s, c = map(int, input().split())
	if s == 1 and c == 0 and N != 1: 
		f = 0
	if flg[s] != -1 and flg[s] != c:
		f = 0
	else:
		flg[s] = c
		ans[s - 1] = c

if f:
	for a in ans:
		print(a, end = "")
else:
	print(-1)
n, m = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(m))

for i in range(10**n):
  k = str(i)
  if len(str(i)) == n:
    if all(str(i)[s-1] == str(c) for s, c in sc):
      print(i)
      exit()
print(-1)
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
for i in range(m):
  s,c = map(int,input().split())
  if s == 1 and c == 0 and n != 1:
    print(-1)
    exit()
  if ans[s-1] != -1 and ans[s-1] != str(c):
    print(-1)
    exit()
  ans[s-1] = str(c)
for i in range(n):
  if ans[i] == -1:
    if i == 0 and n != 1:
      ans[0] = "1"
    else:
      ans[i] = "0"
print(int("".join(ans)))
n,m = map(int,input().split())
if n==1:
    wide = range(0,10)
else:
    wide = range(10**(n-1), 10**n)
st = set(wide)

for _ in range(m):
    s,c = map(int, input().split())
    lst = list(wide)
    st1 = set()
    if s==1 and c==0 and n != 1:
        st &= set()
    for i in wide:
        x = i // 10**(n-s)
        if x % 10 == c:
            st1.add(i)
    st &= st1

lst = list(st)
lst.sort()
lst.append(-1)
print(lst[0])
n,m = map(int, input().split())
num = [0]*n
tf = True
for _ in range(m):
  d = list(map(int, input().split()))
  if d[0]==1 and d[1]==0 and n>1:
    tf = False
    break
  if num[d[0]-1] == 0:
    num[d[0]-1] = d[1]
    continue
  if num[d[0]-1] != d[1]: 
    tf = False
if num[0]==0 and n>1:
  num[0] = 1
if tf:
  ans = 0
  for i in range(n-1,-1,-1):
    ans += num[(n-1)-i]*(10**i)
  print(ans)
else: print(-1)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

s = 10**(n-1)
if s == 1:
    s = 0
for i in range(s, 10**n):
    a = list(map(int, list(str(i))))
    for j in sc:
        if a[j[0]-1] != j[1]:
            break
    else:
        print(i)
        exit()
print(-1)
n,m=list(map(int,input().split()))
cond=[]
for i in range(m):
    index,char=list(map(int,input().split()))
    cond.append((index-1,str(char)))

mini=0
maxi=9
if n==2:
    mini=10
    maxi=99
elif n==3:
    mini=100
    maxi=999

for i in range(mini,maxi+1):
    check=str(i)
    isOk=True
    for index,char in cond:
        if check[index]!=char:
            isOk=False
            break

    if isOk:
        print(check)
        exit()

print(-1)
N, M = map(int, input().split())
S, C = [], []
for i in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
F = False
for i in range(10**(N)):
    t = str(i)
    flag = True
    if len(t) != N:
        continue
    for j in range(M):
        if t[S[j]-1] != str(C[j]):
            flag = False
    if flag:
        print(i)
        F = True
        break
if not F:
    print(-1)
N,M,*sc=map(int,open(0).read().split())
ans=-1
for i in range(10**N):
    i=str(i)
    if len(i)==N and all(i[s-1]==str(c) for s,c in zip(sc[0::2],sc[1::2])):
        ans=i
        break
print(ans)
N,M = map(int, input().split())
d = ['x']*N

flg = 0
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if d[s] == 'x':
    d[s] = c
  if d[s] != c or (s==0 and c==0 and N>1):
    flg = -1

ans = 0
for j in range(N):
  N-=1
  if d[j]=='x':
    if j == 0 and N>0:
      d[j] = 1
    else:
      d[j] = 0
  ans += d[j]*(10**N)

print(flg if flg == -1 else ans)
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
if n == 1:
    a = 0
else:
    a = 10 ** (n - 1)
for i in range(a, 10 ** n):
    test = str(i)
    flag = True
    for j in range(m):
        s = sc[j][0]
        c = sc[j][1]
        if test[s - 1] != str(c):
            flag = False
            break
    if flag == False:
        continue
    else:
        print(i)
        break
else:
    print(-1)
N, M = map(int, input().split())
sc= [list(input().split()) for i in range(M)]
ans = -1
for i in range(10**N):
    if len(str(i)) != N:
        continue
    else:
        cnt = 0
        s = str(i)
        for j in range(M):
            if s[int(sc[j][0])-1] == sc[j][1]:
                cnt += 1
        if cnt == M:
            ans = i
            break
print(ans)
N, M = map(int, input().split())
S = ['a'] * (N+1)
for i in range(M):
    s, c = list(map(int, input().split()))
    if S[s] != 'a' and S[s] != str(c):
        print(-1)
        exit()
    S[s] = str(c)
if S[1] == '0' and N > 1:
    print(-1)
    exit()
for i in range(1, N+1):
    if S[i] == 'a':
        if i == 1 and N > 1:
            S[i] = '1'
        else:
            S[i] = '0'
print(int(''.join(S[1:])))
N, M = list(map(lambda x: int(x), input().split(" ")))

S = ["X"] * N
minus1flag = False
for i in range(M):
  tmp = input().split(" ")
  if S[int(tmp[0]) - 1] in ["X", tmp[1]]:
    S[int(tmp[0]) - 1] = tmp[1]
  else:
    minus1flag = True

if N > 1 and S[0] == "0" or minus1flag:
  print(-1)
elif N == 1 and S[0] in ["0", "X"]:
  print(0)
elif N > 1 and S[0] == "X":
  S[0] = "1"
  print("".join(["0" if s == "X" else s for s in S]))
else:
  print("".join(["0" if s == "X" else s for s in S]))
N, M = map(int, input().split())
SC = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(10**N):
    i = str(i)
    if len(i) != N:
        continue
    for s, c in SC:
        if len(i) < s:
            break
        if i[s - 1] != str(c):
            break
    else:
        print(i)
        exit()

print(-1)
import sys
N,M = map(int,input().split())
cc = [list(map(int, input().split())) for i in range(M)]
if [1,0] in cc:
  if N!= 1:
    print(-1)
    sys.exit()
a,b = [0]*N,['v']*N
for [i,j] in cc:
  a[i-1] = j
  if b[i-1] != 'v' and b[i-1] != j:
    print(-1)
    sys.exit()
  b[i-1] = j
if a[0] == 0:
  if N != 1:
    a[0] = 1
c = ''
for i in a:
  c = c + str(i)
print(c)
n,m=map(int,input().split())
s,c=[],[]

for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    s.append(a)
    c.append(b)
        
for ans in range(10**n):
    st=str(ans)

    if len(st) != n:
        continue

    f=True    
    for i in range(m):
       if st[s[i]] != str(c[i]):
            f=False
          
    if f==True:
        print(ans)
        exit()

print(-1)
n,m=map(int,input().split())
s,c=[],[]
for i in range(m):
    S,C=map(int,input().split())
    s.append(S-1)
    c.append(str(C))

if n==3:
    st,ed=100,1000
elif n==2:
    st,ed=10,100
else:
    st,ed=0,10
ans=-1

for t in range(st,ed):
    t_=list(str(t)) 
    
    for j in range (m):
        if t_[s[j]]!=c[j]:
            break
            
    else:
        ans=t
        break
    
    
print(ans)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = float('inf')
k = 0
if n == 2: k = 10
elif n == 3: k = 100
for i in range(k, 1000):
    flg = True
    for s, c in sc:
        if list(str(i))[s-1] == str(c): continue
        flg = False
    if flg:
        ans = i
        break
if ans == float('inf'): ans = -1
print(ans)
import sys
N, M = map(int, input().split())
num = [0] * (N + 1)
reg = [0] * (N + 1)
if N > 1:
  num[1] = 1

for i in range(M):
  s, c = map(int, input().split())
  if N > 1 and s == 1 and c == 0:
    print (-1)
    sys.exit()
  if reg[s] == 1 and num[s] != c:
    print (-1)
    sys.exit()
  num[s] = c
  reg[s] = 1

result = ""
for i in range(1, N + 1):
  result += str(num[i])
print (result)
N, M = map(int, input().split())
ans = ['*'] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] == '*':
        ans[s - 1] = str(c)
    elif ans[s - 1] != str(c):
        print(-1)
        exit()
if ans[0] == '*' and N > 1:
    ans[0] = '1'
print(-1 if ans[0] == '0' and N > 1 else ''.join(ans).replace('*', '0'))
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
for i in range(10**N):
    stop = True
    for t in sc:
        if i//(10**(N-t[0]))%10 != t[1]:
            stop = False
    if stop:
        if i//(10**(N-1)) > 0 or (N==1 and i==0):
            print(i)
            break
        else:
            stop = True
if not stop:
    print(-1)
n, m = map(int, input().split())
sc = []
for i in range(m):
  sc.append(list(map(int, input().split())))
for i in range(1000):
  aa = str(i)
  f = True
  if len(aa) != n: continue
  for j in range(m):
    s = sc[j][0]
    c = sc[j][1]
    if aa[s-1] != str(c):
      f = False
  if f:
    print(aa)
    exit()
print(-1)
N,M = map(int,input().split())

LIST=[[0,0] for i in range(M)]
for i in range(M):
    LIST[i][0],LIST[i][1] = map(int,input().split())
m=1000
for i in range(999,-1,-1):
    NUM=str(i)
    if len(NUM)!=N:
        continue
    f=0
    for k in range(M):
        if int(NUM[LIST[k][0]-1])!=LIST[k][1]:
            f=1
    if f == 0:
        m=i
if m==1000:
    print(-1)
else:
    print(m)
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))

if n == 1:
    x = 0
elif n == 2:
    x = 10
else:
    x = 100

for i in range(x,1000):
    flag = True
    i_str = str(i)
    for j in range(m):
        a = int(i_str[sc[j][0] - 1])
        b = sc[j][1]
        if a != b:
            flag = False
    if flag:
        print(i)
        exit()
print("-1")
N, M = map(int, input().split())

if N == 1:
    lst = [str(i) for i in range(10)]

elif N == 2:
    lst = [str(i) for i in range(10, 100)]

else:
    lst = [str(i) for i in range(100, 1000)]

for j in range(M):
    s, c = map(int, input().split())
    lst = [i for i in lst if i[s-1] == str(c)]

if len(lst) == 0:
    print(-1)

else:
    print(lst[0])
import sys

n, m = map(int, input().split())
sc = {}
for _ in range(m):
    s, c = map(int, input().split())
    if s in sc:
        if sc[s] != c:
            print(-1)
            sys.exit()
    else:
        sc[s] = c

ans = [0] * n
ans[0] = 1

for s, c in sc.items():
    ans[s-1] = c

# ansチェック
if n != 1 and ans[0] == 0:
    print(-1)
elif n==1 and m==0:
    print(0)
else:
    print(int("".join(map(str, ans))))
N,M = map(int,input().split())
nums = []
for _ in range(M):
    nums.append(list(map(int,input().split())))
    
if N == 1 and M == 0:
    print(0)
    exit()
for i in range(0,1000):
    if len(str(i)) == N:
        for j in range(M):
            s = nums[j][0]
            c = nums[j][1]
            if int(str(i)[s-1]) != c:
                break
        else:
            print(i)
            exit()
print(-1)
n,m=map(int,input().split())
sc=sorted([list(map(int,input().split())) for i in range(m)])
ans=[0 for i in range(n)]
res=True
for i in range(m):
    if (i>0 and sc[i][0]==sc[i-1][0] and sc[i][1]!=sc[i-1][1]) or (n>1 and sc[i][0]==1 and sc[i][1]==0):
        res=False
        break
    else:
        ans[sc[i][0]-1]=sc[i][1]

if n>1 and ans[0]==0:
    ans[0]=1

ans2=int("".join([str(i) for i in ans])) if res else -1
print(ans2)
A=list()
B=list()
n,m=map(int,input().split())
if m==0:
  print([0, 10, 100][n - 1])
  exit()
for i in range(m):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  if a==1 and b==0 and n!=1:
    print(-1)
    exit()
for i in range(1000):
  c=str(i)
  if len(c)==n:
    for j in range(m):
      if c[A[j]-1]!=str(B[j]):
        break
      if j==m-1:
        print(i)
        exit()
print(-1)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = -1
for i in range(10**N):
    n = str(i)
    if len(n) < N:
        continue

    ok = True
    for s, c in sc:
        if s > len(n):
            ok = False
            break
        if n[s-1] != str(c):
            ok = False
            break
    if ok:
        ans = n
        break
print(ans)
n,m = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(m)]
for i in range((10**3) + 1):
    num = str(i)
    flag = True
    if len(num) == n:
        for s,c in lists:
            if num[s-1] != str(c):
                flag = False
        if flag:
            print(num)
            exit()
print(-1)
n,m = map(int,input().split())

s_li=[0]*m
l_li=[0]*m
for i in range(m):
    s_li[i],l_li[i] = map(int,input().split())

for i in range(1000):
    string = str(i)
    if len(string)!=n:
        continue
    flag=True
    for j in range(m):
        if int(string[s_li[j]-1])==l_li[j]:
            continue
        flag=False
        break
    if flag:
        print(string);exit()
print(-1)
def judge(num):
  l = len(num)
  if N != l:
    return False

  for i in range(M):
    if int(num[s[i] - 1]) != c[i]:
      return False

  return True  

N, M = map(int, input().split())
s = []
c = []

for i in range(M):
  a, b = map(int, input().split())
  s.append(a)
  c.append(b)
  
for i in range(1000):
  if judge(str(i)):
    print(i)
    exit()
    
print(-1)
n, m = map(int, input().split())
q = [tuple(map(int, input().split())) for _ in range(m)]

for i in range(1000):
    i = str(i)
    if len(i) != n:
        continue
    flag = True
    for s, c in q:
        if len(i) < s:
            flag = False
            break
        if i[s-1] != str(c):
            flag = False
            break
    if flag:
        print(i)
        exit()
print(-1)
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=list(range(10**(N-1),10**N))
if N==1:A=[0]+A
for i in A:
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)
N,M=map(int,input().split())
li=[0]*N
for i in range(M):
    si,ci=map(int,input().split())
    if li[si-1] != 0 and li[si-1] !=ci:
        print(-1)
        exit(0)
    if si==1 and ci==0:
        if N>1:
            print(-1)
            exit(0)
    li[si-1]=ci
if N>1 and li[0]==0:
    li[0]=1
for i in range(N):
    print(li[i],end="")
n, m = map(int, input().split())
x = [list(map(int, input().split())) for i in range(m)]
for i in range(10**(n-1) if n>1 else 0, 10**n):
    i = str(i)
    for s, c in x:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)
n, m = map(int, input().split())
num = ["n"] * n
for _ in range(m):
    s,c = map(int,input().split())
    if not(num[s-1] == "n" or num[s-1] == str(c)) or (n != 1 and s == 1 and c == 0):
        print(-1)
        exit()
    else:
        num[s-1] = str(c)

op = ""
for ns in range(len(num)):
    if num[ns] == "n": 
        if ns == 0 and n != 1 : op += "1"
        else: op += "0"
    else: op += num[ns]
print(op)
N, M = map(int, input().split())

result = ["" for _ in range(N)]

ls = [list(map(int, input().split())) for _ in range(M)]

save = []

result = -1

if N == 1:
    START = 0
else:
    START = 10 ** (N - 1)
END = 10 ** (N)

for n in range(START, END):
    if all([str(n)[e[0] - 1] == str(e[1]) for e in ls]):
        result = n
        break

print(result)
N, M = map(int, input().split())
N_list = [0] * N
N_set_list = [False] * N

for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  
  if s > N -1 or (s == 0 and c == 0 and N != 1):
    print(-1)
    exit()

  elif N_set_list[s] and (N_list[s] != c):
    print(-1)
    exit()

  else:
    N_list[s] = c
    N_set_list[s] = True

if N_list[0] == 0 and N != 1:
  N_list[0] = 1

print(''.join(map(str, N_list)))
N, M = map(int, input().split())
A = []
for i in range(0, M):
    a = tuple(map(int, input().split()))
    A.append(a)
start = 10**(N-1)
if N == 1:
    start = 0
for x in range(start, 10**N):
    ans = str(x)
    flag = True
    for a in A:
        if ans[a[0]-1] != str(a[1]):
            flag = False
    if flag:
        print(x)
        exit(0)
print(-1)
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = -1
for i in range(m):
    s[i],c[i] = map(int,input().split())
for i in range(1000):
    a = str(i)
    if len(a) != n:
        continue
    if all(a[s[j]-1] == str(c[j]) for j in range(m)):
        ans = i
        break
print(ans)
n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for _ in range(m)]


def ng():
  print('-1')
  exit()


d = {}
for s, c in sc:
  if s in d and d[s] != c:
    ng()
  d[s] = c

ans = [''] * (n + 1)
ans[0] = 'Padding'
for s, c in sc:
  ans[s] = str(c)

if ans[1] == '0' and n!=1:
  ng()

for i in range(1, n + 1):
  if ans[i] == '':
    if i == 1 and n != 1:
      ans[i] = '1'
    else:
      ans[i] = '0'


print(int(''.join(ans[1:])))
n, m = [int(i) for i in input().split()]
s = []
c = []
for i in range(m):
    tmp = [int(j) for j in input().split()]
    s.append(tmp[0])
    c.append(tmp[1])

for i in range(10 ** (n - 1) - int(n == 1) ,10 ** n):
#for i in range(10 ** (n - 1),10 ** n):

    status = True
    for j in range(m):
        if(str(i)[s[j] - 1] != str(c[j])):
            status = False
    if(status):
        print(i)
        exit()
print(-1)
N, M=map(int,input().split())
ret = [-1]*N
fg = True
for i in range(M):
  s, c=map(int,input().split())
  if ret[s-1]==-1:
    ret[s-1]=c
  elif ret[s-1]!=c:
    fg = False
    break
if fg:
  for i in range(N):
    if ret[i]==-1:
      if i==0 and N>1:
        ret[i]=1
      else:
        ret[i]=0
  ans=int(''.join(map(str,ret)))
  if len(str(ans))==N:
    print(ans)
  else:
    print(-1)
else:
  print(-1)
n,m=map(int,input().split())
li=[]
if n==1:
    score="0"
else:
    score="1"+"0"*(n-1)
for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and (s,c)==(1,0):
        print("-1")
        quit()
    li.append([s,c])
    for j in range(len(li)):
        if li[j][0]==s and li[j][1]!=c:
            print("-1")
            quit()
    score=score[:s-1]+str(c)+score[s:]
print(int(score))
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

ans = -1
for i in range(1000):
        can = 1
        t = str(i)
        if len(t)!=n: continue
        for s,c in sc:
                if int(t[s-1])!=c: can = 0
        if can:
                ans = i
                break

if ans<0: print(-1)
else: print(ans)
n,m = map(int,input().split())
s = [0]*m
c = [0]*m
for i in range(m):
    s[i],c[i]=map(int,input().split())

res = "a"*n
for i in range(m):
    if res[s[i]-1] == "a" or res[s[i]-1] == str(c[i]):
        res = res[:s[i]-1] + str(c[i]) + res[s[i]:]
    else:
        print(-1)
        exit()

if n>1 and res[0] == "0":
    print(-1)
    exit()

if n>1 and res[0] == "a":
    res = "1" + res[1:]

res = res.replace("a","0") 
print(int(res))
N, M = map(int, input().split())
X = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and N > 1 and c == 0:
        print(-1)
        exit()
    if X[s-1] < 0:
        X[s-1] = c
    elif X[s-1] != c:
        print(-1)
        exit()

if X[0] < 0: X[0] = 1 if N > 1 else 0
print("".join([str(x) if x >= 0 else "0" for x in X]))
n,m=map(int,input().split())
a = [0]*n
seen = [0]*n
flg = 0
ans = 0
for i in range(m):
  tmp = list(map(int,input().split()))
  if seen[tmp[0]-1] == 0:
    a[tmp[0]-1] = tmp[1]
    seen[tmp[0]-1] = 1
  else:
    if a[tmp[0]-1] == tmp[1]:
      pass
    else:
      flg = 1
if n != 1 and a[0] == 0 and seen[0] == 1:
  flg = 1
if flg == 1:
  print(-1)
else:
  if a[0] == 0 and n != 1:
    a[0] = 1
  print(''.join(map(str, a)))
n, m = map(int, input().split())

A = []
B = []
for i in range(m):
    a, b= map(int, input().split())
    A.append(a)
    B.append(b)
t = 0
ans = 0
for i in range(10000):
    t = 0
    if len(str(i)) == n:
        for j in range(m):
            if int(str(i)[A[j] - 1]) == B[j]:
                t += 1
        if t == m:
            print(i)
            ans = 1
            break
if ans == 0:
    print(-1)
import sys

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

conds = []
for _ in range(m):
  conds.append((input().split()))

for x in range(10 ** 3):
  xs = str(x)
  if len(xs) < n:
    continue

  found = True
  for cond in conds:
    s = int(cond[0]) - 1
    c = cond[1]
    if s >= len(xs):
      found = False
      break

    if xs[s] != c:
      found = False
      break

  if found:
    print(x)
    sys.exit()

print('-1')