peterverebics/CodeNet_Python_118 huggingface dataset:
import collections

n,m = map(int,raw_input().split(' '))
operations = [map(int, raw_input().split(' ')) for _ in range(m)]
def f(operations, n):

	res = [-1] * n

	for s,c in operations:
		s -=1
		if res[s] == -1:
			res[s] = c
		elif res[s] != c:
			return (False, res)
	
	for i in range(len(res)):
		if res[i] == -1: 
			res[i] = 0 if (i or n == 1) else 1
	
	if res[0] == 0 and n > 1:
		return (False, res)
	return (True, res)
f,r = f(operations, n)
print ''.join(map(str,r)) if f else -1
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 0
exist = False
if N == 1:
  x = 0
else:
  x = 10 ** (N - 1)
for i in range(x, 1000):
  s = str(i)
  f = True
  for j in range(M):
    if int(s[sc[j][0] - 1]) != sc[j][1]:
      f = False
      break
  if f:
    ans = i
    exist = True
    break
print(ans if exist else -1)
N, M = map(int, input().split())
if N > 1:
    number = [1] + [0] * (N-1)
else:
    number = [0]
SC = {}
for _ in range(M):
    s, c = map(int, input().split())
    if SC.get(s, c) != c:
        print(-1)
        exit()
    if N >= 2 and (s == 1 and c == 0):
        print(-1)
        exit()
    number[s-1] = c
    SC[s] = c
print("".join(map(str, number)))
n,m = map(int, input().split())

sc = set([tuple(map(int, input().split())) for _ in range(m)])
ans = 0
h = []

for x,y in sc:
  if n != 1 and x == 1 and y == 0:
    print(-1)
    exit()
  if x in h:
    print(-1)
    exit()
  ans += y * (10 ** (n-x))
  h.append(x)
  
if ans < 10**(n-1) and n != 1:
  ans += 10**(n-1)
print(ans)
n,m = map(int,input().split())

rest = []
for i in range(m):
    a,b = input().split()
    rest.append((int(a),b))

done = False

for i in range(0,1000):
    x = str(i)
    if (len(x) == n):
        ok = True
        for t in rest:
            if (x[t[0] - 1] != t[1]):
                ok = False
                break
        if ok:
            print(i)
            done = True
            break

if not done:
    print(-1)
def solve(x):
    x = str(x)
    if len(x) != N:
        return False
    for s, c in P:
        if x[s - 1] != str(c):
            return False
    return True

if __name__ == "__main__":
    N, M = map(int, input().split())
    P = [list(map(int, input().split())) for i in range(M)]
    ans = 10**N
    for i in range(10 ** N - 1, -1, -1):
        if solve(i):
            ans = min(ans, i)
            
    print(ans if ans != 10**N else -1)
n, m = map(int, input().split())
j = [True]*(n + 1)
l = [1] + [0]*(n - 1)
jud = True
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        jud = False
    if j[s]:
        l[s - 1] = c
        j[s] = False
    else:
        if l[s - 1] != c:
            jud = False
if not jud:
    print(-1)
elif n == 1 and m == 0:
    print(0)
else:
    print("".join(list(map(str, l))))
n, m = [int(i) for i in input().split()]
sc = [list(map(int, input().split())) for _ in range(m)]


ans = -1
for i in range(10**(n-1) if n > 1 else 0, 10**n):
    for s, c in sc:
        if str(i)[s-1] != str(c):
            break
    else:
        ans = i
        break
print(ans)
n, m = map(int, input().split())
T = []
A = [str(0) for _ in range(n)]
for i in range(m):
  s, t = map(int, input().split())
  T.append([s, t])
f = True
for i in range(m):
  for j in range(i, m):
    if (T[i][0] == T[j][0] and T[i][1] != T[j][1]) or (T[i][0] == 1 and T[i][1] == 0 and n > 1):
      f = False
      break
  A[T[i][0]-1] = str(T[i][1])
if n == 1 and m == 0:
  print(0)
  exit()
elif A[0] == "0" and len(A) > 1:
  A[0] = "1"
if f: print("".join(A))
else: print(-1)
n,m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]
for i in range(10001):
    if len(str(i)) != n:
        continue
    for j in l:
        if str(i)[j[0]-1] != str(j[1]):
            break
    else:
        print(i)
        exit()
else:
    print(-1)
N, M = map(int, input().split())
A = [-1] * N
valid = True
for i in range(M):
  s, c = map(int, input().split())
  if A[s - 1] < 0:
    A[s - 1] = c
  elif A[s - 1] != c:
    valid = False
if A[0] < 0:
  A[0] = 1 if 1 < len(A) else 0
if 1 < len(A) and A[0] < 1:
  valid = False
for i in range(1, N):
  if A[i] < 0:
    A[i] = 0
print(''.join([str(a) for a in A]) if valid else -1)
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
T = 1
ans = 0
for i in range(M):
  s_i , c_i = map(int, input().split())
  if B[s_i - 1] == 0:
    A[s_i - 1] = c_i
    B[s_i - 1] = 1
  else:
    if A[s_i - 1] != c_i:
      T = 0
if B[0] == 0 and N != 1:
  A[0] = 1
for i in range(N):
  y = A[N - i - 1]
  y = int(y)
  ans = ans + y * 10 ** i
if T == 0:
  ans = -1
elif A[0] == 0 and N !=1 :
  ans = -1
print(ans)
n, m = map(int, input().split())
sc = []
for i in range(m): sc.append(list(map(int, input().split())))

for i in range(10**n):
    flg = True
    if len(str(i)) == n:
        for j in sc:
            # print(int(str(i)[j[0]-1]))
            if int(str(i)[j[0]-1]) != j[1]:
                flg = False
        if flg:
            print(i)
            exit()
print(-1)
#!/usr/bin/env python3
n,m = map(int,input().split())
digit = [-1]*3
for i in range(m):
    s,c =map(int,input().split())
    if digit[s-1] == -1: digit[s-1] = c
    elif digit[s-1] != c: 
        print(-1)
        exit()
if digit[0] == 0 and n != 1:
    print(-1)
    exit()
if (digit[0] == 0 and n == 1) or (n == 1 and m == 0):
    print(0)
    exit()
for i in range(n):
    if digit[i] == -1:
        print(max(1-i,0),end="")
    else: print(digit[i],end="")
N, M = map(int, input().split())
sc = []
for _ in range(M):
    s, c = map(int, input().split())
    sc.append((s - 1, str(c)))

ans = -1
for i in map(str, range(10 ** (N - 1) if N > 1 else 0, 10 ** N)):
    for s, c in sc:
        if i[s] != c:
            break
    else:
        ans = i
        break
print(ans)
# C
#C

N, M = map(int, input().split())

sc = {i+1:[] for i in range(N)}

for _ in range(M):
  si, ci = map(int, input().split())
  sc[si] += [ci]

sc = {k:list(set(v)) for k,v in sc.items()}

flag = True

if N>1 and 0 in sc[1]:
  flag = False

for v in sc.values():
  if len(v)>1:
    flag = False


ans = -1

if flag:
  cand = [0]*N
  if N>1:
    cand[0] = 1
  for k, v in sc.items():
    if len(v)>0:
      cand[k-1] = v[0]
  ans = "".join([str(c) for c in cand])

print(ans)
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

matches = []
for i in range(0, 1000):
    if len(str(i)) == N:
        temp = True
        for s, c in sc:
            if str(i)[s - 1] != str(c):
                temp = False
        if temp: matches.append(i)
print(-1) if len(matches) == 0 else print(min(matches))
n,m = map(int,input().split())
ans = ["-1"]*n

for _ in range(m):
    s,c = input().split()
    s = int(s)-1
    if ans[s] != "-1" and ans[s] != c: 
        print(-1)
        exit()
    ans[s] = c

if n != 1 and ans[0] == "0":
    print(-1)
    exit()



for i in range(n):
    if ans[i] == "-1":
        ans[i] = "0" if i != 0 or n == 1 else "1"

print("".join(ans))
N, M = map(int, input().split())

ans = [-1] * N

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

else:
  if ans[0] == -1:
    ans[0] = 0
    
print(''.join(map(str, ans)))
import sys
N, M = map(int, input().split())
l = []
for i in range(M):
  l.append(list(map(int, input().split())))

ans = -1

if N == 1:
  start, stop = 0, 10  
elif N == 2:
  start, stop = 10, 100
else:
  start, stop = 100, 1000

for i in range(start, stop):
  temp = list(str(i))
  for j in range(N):
    temp[j] = int(temp[j])
  flag = 1
  for j in range(M):
    if temp[l[j][0]-1] != l[j][1]:
      flag = 0
  if flag == 1:
    ans = i
    break
print(ans)
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
if n == 3:
    l = range(100, 1000)
if n == 2:
    l = range(10, 100)
if n == 1:
    l = range(0, 10)
flag = False
for i in l:
    num = str(i)
    if all([num[s-1] == str(c) for s, c in sc]):
        #print(num)
        #exit()
        flag = True
        ans = num
        break
if flag:
    print(num)
else:
    print(-1)
N, M = map(int, input().split())

s = []
c = []

for i in range(M):
    s_e, c_e = map(int, input().split())
    s.append(s_e)
    c.append(c_e)

ans = -1

for i in range(1000):
    str_i = str(i)
    len_str_i = len(str_i)
    if len_str_i != N:
        continue
    else:
        for k in range(M):
            if str_i[s[k]-1] != str(c[k]):
                break
        else:
            ans = i
            break

print(ans)
n, m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

ans = -1

for i in range(1000):
    s_i = str(i)
    if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc):
        ans = i
        break

print(ans)
n, m = map(int, input().split())
ss = list()
cs = list()
for i in range(m):
    s, c = map(int, input().split())
    ss.append(s)
    cs.append(c)

if n != 1:
    data_range = range(10 ** (n - 1), 10 ** n)
else:
    data_range = range(0, 10)


def is_ok(i):
    for s, c in zip(ss, cs):
        if int(str(i)[s - 1]) != c:
            return False
    return True

for i in data_range:
    if is_ok(i):
        print(i)
        break
else:
    print('-1')
import sys
n,m=map(int,input().split())
number=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0 and n!=1:
        print(-1)
        sys.exit()
    if number[s-1]==0:
        number[s-1]=c
    elif number[s-1]==c:
        continue
    else:
        print(-1)
        sys.exit()
if number[0]==0 and n!=1:
    number[0]=1
answer=''
for i in range(len(number)):
    answer+=str(number[i])
print(int(answer))
N, M = map(int, input().split())
if N==1 and M==0:
  print(0)
  import sys
  sys.exit()
ans = [-1]*N
for i in range(M):
  s,c = map(int,input().split())
  if ans[s-1]!=-1 and ans[s-1]!=c:
    print(-1)
    break
  ans[s-1] = c
else:
  for i in range(N):
    if ans[i]==-1:
      if i!=0:
        ans[i] = 0
      else:
        ans[i] = 1
    ans[i] = str(ans[i])
  a = ''.join(ans)
  if a[0]=='0' and len(a)>1:
    print(-1)
  else:
    print(a)
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]

l=10**(n-1)
if n==1:
    l=0
for i in range(l,10**n):
    s=str(i)
    for x,y in a:
        if s[x-1]!=str(y):
            break
    else:
        print(i)
        exit()
print(-1)
n, m = [int(i) for i in input().split()]
s, c = [], []
for _ in range(m):
    a, b = [int(i) for i in input().split()]
    a -= 1
    s.append(a)
    c.append(b)

for ans in range(1000):
    st = str(ans)
    if len(st) != n:
        continue

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

print(-1)
n,m = map(int,input().split())
done = [0]*n
ans = [0]*n
for i in range(m):
  s,c = map(int,input().split())
  if done[s-1] != 0 and ans[s-1] != c:
    print(-1)
    exit()
  elif n != 1 and s == 1 and c == 0:
    print(-1)
    exit()
  else:
    done[s-1] = 1
    ans[s-1] = c
ans_f = str()
for j in ans:
  ans_f += str(j)
if n>1 and ans_f[0] == "0":
  print("1"+ans_f[1::])
else:
  print(ans_f)
N, M = map(int, input().split())
digits = [-1 for _ in range(N+1)]
for __ in range(M):
  digit, num = map(int, input().split())
  if digit == 1 and num == 0 and N != 1:
    print(-1)
    exit()
  elif digits[digit] != -1 and num != digits[digit]:
    print(-1)
    exit()
  else:
    digits[digit] = num
answer = 0
for i in range(1, N+1):
  if digits[i] == -1:
    if i == 1 and N != 1:
      answer += 1*10**(N-i)
  else:
    answer += digits[i]*10**(N-i)
print(answer)
n, m = map(int, input().split())

fail = False
result = {}

for i in range(0, m):
    s, c = map(int, input().split())
    key = n-s
    if key in result and result[key] != c:
        fail = True
        break
    result[key] = c

if n > 1:
    if n-1 in result and result[n-1] == 0:
       fail = True
    if not(n-1 in result):
        result[n-1] = 1

if fail:
    print(-1)
else:
    res = 0
    for i in range(0, n):
        if i in result:
            res += 10 ** i * result[i]
    print(res)
import sys

N, M = map(int, input().split())

S = []
C = []
for m in range(M):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)

for i in range(10**N):
  tes = str(i)

  if len(tes) != N:
    continue
  
  flag = True
  for s, c in zip(S, C):
    if tes[s-1] != str(c):
      flag = False
  if flag:
    print(tes)
    sys.exit()


print(-1)
n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]
ans=-1
if n==1:
    r=range(10)
elif n==2:
    r=range(10,100)
else:
    r=range(100,1000)
for i in r :
    i=str(i)
    for j ,k in SC:
        if i[j-1]!=str(k):
            break
    else:
        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**3):
    if (len(str(i))==n):
        flag=1
        for s,c in sc:
            if str(i)[s-1] != str(c):
                flag=0
        if flag==1:
            ans =i
            break
print(ans)
N,M=map(int,input().split())
A = [-1]*N
for _ in range(M):
  s,c=map(int,input().split())
  s = s-1
  if A[s] != -1 and A[s] != c:
    print(-1)
    exit()
  A[s] = c

if N == 1:
  if A[0]==-1:
    print(0)
  else:
    print(A[0])
  exit()

if A[0] == 0:
  print(-1)
  exit()
if A[0] == -1: A[0] = 1
for i,a in enumerate(A):
  if a == -1:
    print(0,end='')
  else:
    print(a,end='')
n, m = map( int, input().split())
 
a = [ -1 ] * n
 
ret = 0
for _ in range(m):
  s, c = map( int, input().split() )
  if ( not ( a[ s - 1 ] in [ - 1, c ] ) ) or ( ( n > 1 ) and ( s == 1 ) and ( c == 0 ) ):
    ret = -1
    break
  a[ s - 1 ] = c
if ret != -1:
  ret = ""
  for i in range( n ):
    if a[i] == -1:
      if ( n > 1 ) and ( i == 0 ):
        a[ i ] = 1
      else:
        a[ i ] = 0
    ret += str( a[ i ] )
print( ret )
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = list(str(i))
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[j][0]-1] == str(sc[j][1]))
        if (f):
            ans = i
            break

print(ans)
import sys
n,m = map(int, input().split())
SCs = [list(map(int, input().split())) for _ in range(m)]
for i in range(10**n):
  X=str(i)
  tf=True
  if len(X)==n:
    for j in SCs:
      if X[j[0]-1]!=str(j[1]):
        tf=False
        break
    if tf:#全ループ終わって条件を満たしていれば
      print(i)
      sys.exit()
print(-1)
N,M=map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]

if N>1:
    s = list('1'+'0'*(N-1))
else:
    s=list('0')
d = {1:-1,2:-1,3:-1}
sw = 0
for i in range(M):
    s[sc[i][0]-1] = str(sc[i][1])
    if d[sc[i][0]]==-1: 
        d[sc[i][0]] = sc[i][1]
    elif d[sc[i][0]]!=sc[i][1]:
        sw=1
if sw==1:
    print(-1)
elif s[0]=='0' and N>1:
    print(-1)
else:
    print(''.join(s))
def resolve():
	n,m = map(int,input().split())
	sc = [tuple(map(int,input().split())) for _ in range(m)]
	for i in range((10**(n-1) if n!=1 else 0),10**n):
		c = 1
		for j in sc:
			if str(i)[j[0]-1] != str(j[1]):
				c = 0
				break
		if c: break
	print(i if c else -1)
    
resolve()
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    i = str(i)
    if len(i) != n:
        continue
    for [x, y] in lst:
        if i[x-1] != str(y):
            break
    else: 
        print(i)
        exit()

print(-1)
n, m = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(m)]
for i in range(10 ** n):
	flag = True
	st = str(i)
	if len(st) != n:
		continue
	for s, c in S:
		if int(st[s - 1]) != c:
			flag = False
			break
	if flag:
		print(int(st))
		break
else:
	print(-1)
N,M = map(int,input().split())
A = [-1]*N
ans = 0
for i in range(M):
    s,c = map(int,input().split())
    if A[s-1]!=-1 and A[s-1]!=c:ans=-1
    else:
        A[s-1]=c
if N==1:
    print(max(A[0],0) if ans!=-1 else ans)
    exit()
for i in range(N):
    if i==0 and A[i]==0:ans=-1
    if A[i]==-1:A[i]=0
    if i==0:A[i]=max(A[i],1)
    A[i] = str(A[i])
print(-1 if ans==-1 else "".join(A))
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]

def check(x):
  x=str(x)#文字に変換
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[s-1]!=str(c):
      return False
  return True

for i in range(1000):
  if check(i):
    print(i)
    exit()
print(-1)
n, m = map(int, input().split())

t = [-1] * n
for _ in range(m):
   s, c = map(int, input().split())
   s -= 1

   if (t[s] != -1 and t[s] != c):
      print(-1)
      exit()
   t[s] = c

if (n > 1):
   if (t[0] == 0):
      print(-1)
      exit()

   if (t[0] == -1):
      t[0] = 1

   for i in range(1, n):
      if (t[i] == -1):
         t[i] = 0

else:
   if (t[0] == -1):
      t[0] = 0

print(''.join(map(str, t)))
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
 
for i in range(1000):
    s = str(i)
    if len(s) != n:
      continue
    if all(s[a - 1] == str(b) for a, b in sc):
        print(i)
        exit()
 
print(-1)
N, M = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(M)]
minN = 0 if N == 1 else 10 ** (N - 1)

for t in range(minN, 10 ** N):
    for s, c in C:
        if (t // (10 ** (N - s))) % 10 != c:
            break
    else:
        ans = t
        break
else:
    ans = -1

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

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

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for m in range(M)]
for i in range(10**N):
    if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)
import sys
 
def LI():
  return [int(s) for s in input().split()]
 
N,M = LI()

check = {}
 
for i in range(M):
  s,c = LI()
  if N >= 2 and s == 1 and c == 0:
    print(-1)
    sys.exit()
  
  if s in check.keys():
    if check[s] != c:
      print(-1)
      sys.exit()
      
  check[s] = c

answer = ['0']*N
if len(answer) > 1:
	answer[0] = '1'

for s,c in check.items():
  answer[s-1] = str(c)

print(int(''.join(answer)))
n, m = map(int, input().split())

A = [-1] * n

for i in range(m):
	s, c = map(int, input().split())
	if A[s-1] == c:
		continue
	if A[s-1] != -1:
	# if A[s-1] != -1 or (s == 1 and c == 0):
		print(-1)
		exit()
	A[s-1] = c
if n == 1:
	print(0 if A[0] == -1 else A[0])
else:
	if A[0] == 0:
		print(-1)
		exit()
	else:
		print(1 if A[0] == -1 else A[0], end='')
		for a in A[1:]:
			print(0 if a == -1 else a, end='')
N,M=map(int,input().split())
sc=[]
for i in range(M):
  sc.append(list(map(int,input().split())))

ans=-1
cnt=10**(N-1)
if cnt==1:cnt-=1
while True:
  if len(str(cnt))>N:break
  if len(str(cnt))!=N:continue
  ret=True
  for i in range(M):
    if str(cnt)[sc[i][0]-1]!=str(sc[i][1]):
      ret=False
      break
  if ret:
    ans=cnt
    break
  cnt+=1
print(ans)
def is_valid(n, conditions):
    ns = [int(i) for i in str(n)]
    return all(ns[s - 1] == c for s, c in conditions)


N, M = map(int, input().split())

sc = []
for _ in range(M):
    s, c = map(int, input().split())
    sc.append((s, c))

candidates = (i for i in range(1000) if len(str(i)) == N and is_valid(i, sc))

try:
    print(next(candidates))
except StopIteration:
    print(-1)
def main():
  n, m = map(int, input().split(' '))

  if m == 0:
    print(10 ** (n - 1) if n > 1 else 0)
    return

  num_list = [0] * n
  done_list = [-1] * n

  for _ in range(m):
    s, c = map(int, input().split(' '))

    if (n > 1 and s == 1 and c == 0) or (done_list[s - 1] != -1 and done_list[s - 1] != c):
      print(-1)
      exit()

    num_list[s - 1] = c
    done_list[s - 1] = c

  if num_list[0] == 0:
    num_list[0] = 0 if n == 1 else 1

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

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

s = [0]*n

for i in range(m):
    keta, num = map(int,input().split())
    if keta == 1 and num == 0 and n != 1:
        print(-1)
        exit()
    if s[keta-1] == 0 or s[keta-1] == num:
        s[keta-1] = num
    else:
        print(-1)
        exit()

if s[0] != 0:
    print(*s, sep ="")
elif s[0] == 0 and n == 1:
    print(0)
elif s[0] == 0 and n != 1:
    s[0] = 1
    print(*s, sep ="")
else:
    print(-1)
n, m = map(int, input().split())
x = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if x[s] != -1 and x[s] != c:
        print(-1)
        quit()
    x[s] = c
if n > 1 and x[0] == 0:
    print(-1)
    quit()

if x[0] == -1:
    x[0] = 1 if n > 1 else 0
for i in range(1, n):
    if x[i] == -1:
        x[i] = 0
print(''.join(map(str, x)))
n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't' and n >1:
    ans[0]=str(1)

ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)
N, M = map(int, input().split())
ans = [-1] * N
for _ in range(M):
    i, n = map(int, input().split())
    if (ans[i-1] == -1 or ans[i-1] == n) and not(N > 1 and i == 1 and n == 0):
        ans[i-1] = n
    else:
        print(-1)
        exit()
ans = [n if n != -1 else 0 for n in ans]
if ans[0] == 0 and N > 1:
    ans[0] = 1

print(*ans, sep='')
def main():
    N, M = (int(x) for x in input().split())
    SC = [list(map(int, input().split())) for _ in range(M)]
    for i in range(10 ** N):
        _str = str(i)
        k = True
        if len(_str) == N:
            for j in range(M):
                if _str[SC[j][0]-1] != str(SC[j][1]):
                    k = False
            if k:
                return print(i)
    return print('-1')

if __name__ == "__main__":
    main()
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]

ans=-1
for i in range(1000):
    OK=True
    STR=str(i)
    if len(STR)==n:
        for g in range(m):
            if int(STR[sc[g][0]-1])!=sc[g][1]:
                OK=False
                break
    else:
        OK=False
    if OK:
        ans=i
        break
print(ans)
N, M = map(int, input().split())
A  = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
if N != 1 and A[0] == 0:
  print(-1)
  exit()
elif A.count(-1) == N and N != 1:
  print(1 * 10 ** (N - 1))
  exit()
elif A[0] == -1:
  if N == 1:
    A[0] = 0
  else:
    A[0] = 1
B = [A[j] * 10 ** (N - 1 - j) for j in range(N) if A[j] > 0]
print(sum(B))
N, M = map(int, input().split())
n = [-1 for i in range(N)]

judge = True
i = 0
while i < M:
	s, c = map(int, input().split())
	if n[s-1] == -1:
		n[s-1] = c
	else:
		if c != n[s-1]:
			judge = False

	i += 1

if N != 1 and n[0] == 0:
	judge = False

if N != 1 and n[0] == -1:
	n[0] = 1
elif n[0] == -1:
	n[0] = 0

if judge:
	num = 0
	for j in n:
		if j != -1:
			num += j
		num *= 10
	print(int(num/10))
else:
	print(-1)
(n, m) = [int(s) for s in input().split()]

p = []

for i in range(0, m):
    p.append([int(s) for s in input().split()])

ans = -1
for i in range(0, 1000):
    r = True

    si = str(i)

    if len(si) == n:

        for (s, c) in p:
            if len(si) <= s - 1 or si[s-1] != str(c):
                r = False
                break
    else:
        r = False

    if r:
        ans = i
        break

print(ans)