peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
import math

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

s, c = [0] * M, [0] * M
for i in range(M):
	s[i], c[i] = map(int, input().split())

for i in range(0 if N == 1 else 10 ** (N - 1), 10 ** N):
	x = str(i)
	if M == 0:
		print(i)
		sys.exit(0)
	for j in range(M):
		if x[s[j] - 1] != str(c[j]):
			break
		elif j == M - 1:
			print(i)
			sys.exit(0)

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

ans = [-1 for _ in range(n)]
for sci in sc:
	if ans[sci[0]-1] == -1:
		ans[sci[0]-1] = sci[1]
	elif ans[sci[0]-1] != sci[1]:
		print(-1)
		exit(0)

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

ansint = 0
for i, a in enumerate(ans):
	ansint *= 10
	if a == -1:
		if i == 0 and n != 1:
			ans[i] = 1
		else:
			ans[i] = 0
	ansint += ans[i]

print(ansint)
n, m = map(int, input().split(' '))
sc = []
for i in range(m):
    a, b = map(int, input().split(' '))
    sc.append((a, b))
d = '0' * n
for i, j in sc:
    if d[i - 1] != '0' and int(d[i - 1]) != j or n > 1 and i == 1 and j == 0:
        d = '-1'
        break
    d = d[:i - 1 if i > 1 else 0] + str(j) + d[i if i < 3 else 3:]
if d[0] == '0' and n > 1:
    d = '1' + d[1:]
print(d)
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n, m = na()
ans = 10 ** 9 + 7
sc = [na() for _ in range(m)]
for i in range(10 ** n):
    st = str(i)
    if len(st) != n:
        continue
    ok = True
    for s, c in sc:
        if int(st[s-1]) != c:
            ok = False
    if ok:
        print(st)
        exit(0)
print(-1)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
sc = [list(map(int, readline().split())) for _ in range(m)]
max_dig = 10 ** n
min_dig = 10 ** (n - 1)
if n == 1:
    min_dig -= 1
for dig in range(min_dig, max_dig):
    dig = str(dig)
    for s, c in sc:
        if dig[s - 1] != str(c):
            break
    else:
        print(dig)
        exit()
print(-1)
def MI():return map(int,input().split())
N,M=MI()
sc=[]
for i in range(M):
    x,y=MI()
    sc.append((x,y))
for i in range(0,10**3):
    h=str(i)
    if len(h)==N:
        if all([h[s-1]==str(c) for (s,c) in sc]):
            print(i)
            exit()
print(-1)
n,m = map(int, input().split())
s=[]
for i in range(m):
  s.append(list(map(int, input().split())))

for i in range(1000):
  if len(str(i)) != n:
    continue
  for si in s:
    if len(str(i)) < si[0]:
      break
    if str(i)[si[0]-1] != str(si[1]):
      break
  else:
    print(i)
    break
else:
  print(-1)
def get_ints():
    return list(map(int, input().split()))

n, m = get_ints()
digits = [-1 for i in range(n)]

for i in range(m):
    s, c = get_ints()
    s -= 1
    if digits[s] >= 0 and digits[s] != c:
        print(-1)
        exit(0)
    digits[s] = c

if digits[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
    exit(0)

if n > 1 and digits[0] == -1:
    digits[0] = 1

print(''.join(map(lambda x: str(max(0, x)), digits)))
n,m = map(int,input().split())
sc = [input() for _ in range(m)]
ans = -1

start = 10**(n-1)
if n == 1:
    start = 0

for i in range(start,10**n):
    i = str(i)
    ok = 0
    
    for j in sc:
        s,c = j.split()
        
        if i[int(s)-1] == c:
            ok += 1
        
    if ok == m:
        ans = int(i)
        break
        
print(ans)
n, m = (int(x) for x in input().split())
ans = [None for _ in range(n)]
fail = False
for _ in range(m):
    s,c = (int(x) for x in input().split())
    s -=1
    if ans[s] is None:
        ans[s] = c
    elif ans[s] != c:
        fail = True
        break
if fail or (ans[0] == 0 and n > 1):
    print(-1)
else:
    if ans[0] is None and n > 1:
        ans[0] = 1
    elif ans[0] is None and n == 1:
        ans[0] = 0
    print(''.join((str(i) if i is not None else '0' for i in ans)))
N, M = map(int, input().split())
sc = [[int(i) for i in input().split()] for _ in range(M)]

if N == 1 :
  start = 0
else :
  start = 10 ** (N - 1)
  
ret = float('inf')
for i in range(start, 10 ** N) :
  i = str(i)
  for s, c in sc :
    if int(i[s - 1]) != c :
      break
  else :
    ret = min(ret, int(i))
    
if ret == float('inf') :
  print(-1)
else :
  print(ret)
N, M = map(int, input().split())

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

if N == 1:
    r = range(0, 10)
elif N == 2:
    r = range(10, 100)
else:
    r = range(100, 1000)

for i in r:
    str_i = str(i)

    flag = True
    for s, c in S_C:
        if str_i[s - 1] != str(c):
            flag = False
            break

    if flag:
        print(i)
        quit(0)

print(-1)
import sys
n, m = map(int, input().split())
num = [-1]*n

if n == 1 and m == 0:
  print(0)
  sys.exit()

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

  # 一桁目が0
  if s == 1 and c == 0 and n > 1:
    print(-1)
    sys.exit()
  # 同じ桁が指定される
  if num[s-1] != -1 and num[s-1] != c:
    print(-1)
    sys.exit()
  num[s-1] = c

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

for i in num:
  print(i, end='')
n,m=map(int,input().split())
a = [-1]*(n+1)

ans = 0
for i in range(m):
  s,c=map(int,input().split())
  if a[s] == -1 or a[s] == c:
    a[s] = c
  else:
    print(-1)
    exit()
if n == 1:
  print(max(0, a[1]))
  exit()
if a[1] == 0:
  if n>1:
    print(-1)
    exit()
  else:
    print(ans)
else:
  ans = max(1, a[1])
  for i in range(2, n+1):
    ans = ans*10+max(0, a[i])
print(ans)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
start=10**(n-1)
if n==1:
    start=0
for i in range(start,1001):
    i = str(i)
    for s,c in sc:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)
N,M = map(int,input().split())
array = [10]*N
T_F = True

for i in range(M):
  s,c = map(int,input().split())
  if s>N or (array[s-1] != 10 and array[s-1] !=c) or (s == 1 and c == 0 and N != 1):
    T_F = False
    break
  else:
    array[s-1] = c

ans = 0
if T_F:
  for i in range(N):
    if array[i] == 10:
        array[i] = 0
    ans += array[i]*(10**(N-i-1))
  if array[0] or N == 1:
    print(ans)
  else:
    print(ans+10**(N-1))
else:
  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(_c)

for i in range(1000):
	*t, = map(int, list(str(i)))

	if len(t) != n:
		continue

	ok = True
	for j in range(m):
		if t[s[j]]!=c[j]:
			ok = False
			break
 
	if ok:
		print(i)
		quit()

print(-1)
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

for x in range(1000):
    keta = 1
    nx = x // 10
    d = []
    d.append(x%10)
    while nx:
        keta += 1
        d = [nx%10] + d
        nx //= 10
    if keta != n: continue
    ok = True
    for i in range(m):
        if d[p[i][0] - 1] != p[i][1]: ok = False
    if ok: 
        print(x)
        exit() 
print(-1)
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]

if n==1 and all([i[1]==0 for i in li]):
    print(0)
    exit()
for i in range(10**(n-1),10**n):
    p = list(map(int,list(str(i))))
    for s,c in li:
        if p[s-1] != c:break
    else:
        print(i)
        exit()
print(-1)
# input
N, M = map(int, input().split())

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

ans = -1

# check
for i in range(1000):
    str_i = str(i)

    if N < len(str_i):
        break

    if N == len(str_i) and False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
        ans = i
        break

print(ans)
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))
ans = []
for i in range(10 ** N):
    a = list(str(i))
    if len(a) != N:
        continue
    ansFlag = True
    for i in range(M):
        if a[S[i]] != C[i]:
            ansFlag = False
    if ansFlag:
        ans = a
        break

if ans == []:
    print(-1)
else:
    print("".join(ans))
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
S = [1] + [0] * (N-1)
sc = sorted(sc, key=lambda x: x[0])


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


if N != 1 and [1, 0] in sc:
    print(-1)
elif len(list(set([i[0] for i in sc]))) != len(list(get_unique_list(sc))):
    print(-1)
elif N == 1 and M == 0:
    print(0)
else:
    for i in sc:
        S[i[0]-1] = "{}".format(i[1])

    print(*S, sep="")
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)
for i in range(10 **(n + 1)):
  tmp = str(i)
  if len(tmp) == n and all([tmp[s[j] - 1] == str(c[j]) for j in range(m)]):
    print(tmp)
    exit()
print(-1)
n, m = map(int,input().split())
SC = [list(map(int, input().split())) for _ in range(m)]

def check(num):
    num = str(num)
    if len(num) != n:
        return False

    for s, c in SC:
        if num[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())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = ["0"] * N
if N > 1: ans[0] = "1"
rep = {}

ok = True
for s, c in sc:
  ans[s-1] = str(c)
  if s in rep and rep[s] != str(c):
    ok = False
  else:
    rep[s] = str(c)

if ok:
  if ans[0] == "0" and N > 1:
    ok = False

print("".join(ans) if ok else -1)
N, M = list(map(int, input().split(' ')))
r = [ None for i in range(N) ]

illegal = False
for i in range(M):
  s, c = list(map(int, input().split(' ')))
  if r[s-1] is not None and r[s-1] != c:
    illegal = True
    break
  r[s-1] = c

v = -1
if not illegal:
  for i in range(N):
    if r[i] is None:
      if i == 0 and N != 1:
        r[i] = 1
      else:
        r[i] = 0
  v = sum(r[i] * 10**(N-1-i) for i in range(N))
  if v < 10**(N-1) and not (N == 1 and v == 0):
    v = -1

print(v)
def check(x):
  if len(str(x))!=N:
    return False
  for i in range(M):
    if str(x)[S[i]]!=str(C[i]):
      return False
  return True

N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  S.append(s)
  C.append(c)
#print(S,C)
for i in range(1000):
  if check(i):
    print(i)
    exit()   
print(-1)
# 別解: 総当たり(Brute Force)で解く

n, m = [int(i) for i in input().split()]
s = []
c = []
for _ in range(m):
    i, k = [int(i) for i in input().split()]
    s.append(i)
    c.append(k)

res = -1
start = 10**(n-1) if n > 1 else 0
for i in range(start, 10**n):
    i2s = str(i)
    for ss, cc in zip(s, c):
        if i2s[ss-1] != str(cc):
            break
    else:
        res = i
        break

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

sets = []
for i in range(M):
  s,c = input().split()
  sets.append((s,c))

start = 0
if N != 1:
  start = 10**(N-1)

for n in range(start,10**N):
  for s,c in sets:
    if str(n)[int(s)-1] == c:
      continue
    else:
      break
  else:
    print(n)
    break
else:
  print(-1)
import sys

n, m = map(int, input().split())
N = [None]*n
for _ in range(m):
    s, c = map(int, input().split())
    if s-1 == c == 0 and n != 1:
        print(-1)
        sys.exit(0)
    if N[s-1] == None or N[s-1] == c:
        N[s-1] = c
    else:
        print(-1)
        sys.exit(0)
if N[0] == None and n > 1:
    N[0] = 1
for i in range(n):
    if N[i] == None:
        N[i] = 0
    print(N[i], end="")
print()
n, m = map(int, input().split())
req = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    num = str(i)
    if len(num) != n:
        continue
    ok = True
    for s, c in req:
        if int(num[s - 1]) != int(c):
            ok = False
    if ok:
        print(num)
        exit()
print(-1)
N, M = map(int, input().split())
A=[0]*N
ans=0
e=0
for i in range(M):
  s, c = map(int, input().split())
  if(s==1 and c==0 and N!=1):
    print(-1)
    e=1
    break
  if A[s-1]==0 or A[s-1]==c:
  	A[s-1]=c
  else:
    print(-1)
    e=1
    break
if A[0]==0 and N!=1:
  A[0]=1
for i in range(N):
  ans+=A[i]*(10**(N-i-1))
if e==0:
  print(ans)
N,M = map(int,input().split())
s,c=[],[]
for _ in range(M):
    s_,c_ = map(int,input().split())
    s.append(s_)
    c.append(c_)

if N != 1:
    a,b=10**(N-1),10**N
else:
    a,b=0,10

for i in range(a,b):
    ok = True
    num = str(i)
    for k in range(M):
        if num[s[k]-1] != str(c[k]):
            ok = False
    if ok:
        print(i)
        exit()
print(-1)
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())

ans = -1

for num in range(0, 1000):
    num_car = str(num)

    con1 = len(num_car) == n

    con2 = True
    for i in range(m):
        if con1 and num_car[s[i] - 1] != str(c[i]):
            con2 = False

    if con1 and con2:
        ans = num
        break

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

if N == 1:
  a, b = 0, 10**N
elif N >= 2:
  a, b = 10**(N-1), 10**N

ans = '-1'
for i in range(a, b):
  flag = True
  for j in range(M):
    if str(i)[s_c[j][0]-1] != str(s_c[j][1]):
      flag = False
  if flag:
    ans = i
    break

print(ans)
from collections import defaultdict
def solve():
  N, M = map(int, input().split())
  d = defaultdict(lambda: -1)
  for i in range(M):
    x,y = map(int, input().split())
    if d[x]>=0 and d[x]!=y:
      return -1
    if N>1 and x==1 and y==0:
      return -1
    d[x] = y
  if N==1 and d[1]==-1:
    return 0
  if d[1]==-1:
    d[1] = 1
  for i in range(2,N+1):
    if d[i]==-1:
      d[i] = 0
  ans = ''
  for i in range(1,N+1):
    ans += str(d[i])
  return ans
print(solve())
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    ans=str(i)
    if len(ans)==n and all(ans[s-1]==str(c) for s,c in sc):
        print(ans)
        exit()
print(-1)
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
i = 0

while len(str(i))<=N:
  k = 0
  if len(str(i))!=N:
    i += 1
    continue
  for el in sc:
    if str(i)[el[0]-1] == str(el[1]):
      k += 1
  if k == M:
    print(i)
    exit()
  i += 1
  
print(-1)
def main():
    n, m = [int(s) for s in input().strip().split()]
    S, C = [], []
    for _ in range(m):
        s, c = [int(s) for s in input().strip().split()]
        S.append(s)
        C.append(str(c))
    
    for x in range(1000):
        x = str(x)
        if len(x) == n and all(x[s - 1] == c for s, c in zip(S, C)):
            print(x)
            return
    print(-1)


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

start = 10 ** (N - 1) if N != 1 else 0

for i in range(start, 10 ** N):
    flag = 1
    si = str(i)
    for s, c in SC:
        if si[s - 1] != str(c):
            flag = 0
            break
    if flag:
        print(i)
        exit()
print(-1)
n,m=map(int,input().split())
if n==1 and m==0:
  print(0)
  exit()
c=[list(map(int,input().split())) for i in range(m)]
if [1,0] in c and n>1:
  print(-1)
  exit()
num=[1]+[0]*(n-1)
try:
  for i in c:
  	num[i[0]-1]=i[1]
except:
  print(-1)
  exit()
for i in c:
  if num[i[0]-1]!=i[1]:
    print(-1)
    exit()
print(int("".join(map(str,num))))
from collections import defaultdict as d
n, m = map(int, input().split())
dico = d(set)
tab = [-1] * n
for _ in range (m):
  s, c = map(int, input().split())
  dico[s].add(c)
  if len(dico[s]) == 2:
    print(-1)
    exit()
  tab[s - 1] = c
if n == 1:
  print(max(0, tab[0]))
else:
  if tab[0] == 0:
    print(-1)
  else:
    if tab[0] == -1:
      tab[0] = 1
    f = ''
    for i in tab:
      if i == -1:
        f += '0'
      else:
        f += str(i)
    print (f)
N, M = map(int, input().split())
answer = [0 for _ in range(N)]

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

    if not N == 1:
        if s == 1 and c == 0:
            print(-1)
            exit()

    if answer[s-1] == 0:
        answer[s-1] = c
    else:
        if not answer[s-1] == c:
            print(-1)
            exit()

if answer[0] == 0 and not N == 1:
    answer[0] = 1

print("".join(list(map(str, answer))))
#graph implementation
import math
n,m=map(int,input().split())
ans=['l']*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='l':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
if ans[0]=='l' and n>1:
    ans[0]=1
for i in range(n):
    if ans[i]=='l':
        ans[i]=0
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for j 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)
N, M=map(int, input().split())
ans=["-1"]*N
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0 and N!=1:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  if ans[0]=="-1" and N!=1:
    ans[0]="1"
  elif M==0 and N==1:
    ans[0]="0"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
start=10**(n-1)
end=10**n
if n == 1:
    start = 0
for i in range(start,end):
    i=str(i)
    for s,c in sc:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print(-1)
N,M = map(int, input().split())
s1 = []
s2 = []
flg = True
for i in range(M):
  n1,n2 = map(int,input().split())
  s1.append(n1)
  s2.append(n2)
for i in range(1000):
  flg = True
  num = [int(x) for x in list(str(i))]
  if len(num) == N:
    for j in range(M):
      if s2[j] != num[s1[j] - 1]:
        flg = False
    if flg:
      print(i)
      exit()
print(-1)
N, M = map(int,input().split())
S = "0" * N

for i in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and N != 1:
        print("-1")
        quit()
    elif S[s-1] == "0" or S[s-1] == str(c):
        S = S[0:s-1] + str(c) + S[s:]
    else:
        print("-1")
        quit()

if S[0] == "0" and N != 1:
    S = "1" + S[1:]

print(S)
def main():
    n, m = list(map(int, input().split()))
    x = []
    for _ in range(m):
        x.append(list(map(int, input().split())))
    for i in range(1000):
        y = str(i)
        if len(y) != n:
            continue
        
        for s, c in x:
            if y[s-1] != str(c):
                break
        else:
            print(i)
            return
    print(-1)

if __name__ == '__main__':
    main()
f = True
n,m=map(int,input().split())
number = [-1 for i in range(n)]
for i in range(m):
  s,c=list(map(int,input().split()))
  s -= 1
  if s == 0 and c == 0 and n > 1:
    f = False
  elif number[s] == -1 or number[s] == c:
    number[s] = c
  else:
    f = False
if not f:
  print(-1)
elif n == 1:
  if number[0] == -1:
    print(0)
  else:
    print(number[0])
else:
  if number[0] == -1:
    number[0] = 1
  for i in range(1,n):
    if number[i] == -1:
      number[i] = 0
  print(''.join(map(str,number)))
n,m = map(int,input().split())
a = [list(map(int,input().split()))for i in range(m)]

for i in range(10**n):
    tmp = str(i)
    if len(tmp) == n:
        f = True
        for s,c in a:
            if tmp[s-1] != str(c):
                f = False
                break
        if f :
            print(i)
            exit()
print(-1)
n, m = map(int, input().split())
s=[]
c=[]
num=[]
for i in range(m):
  S, C = map(int, input().split())
  s.append(S)
  c.append(C)

for i in range(10**(n+1)):
  String=str(i)
  if len(String) == n and all([String[s[j]-1] == str(c[j]) for j in range(m)]):
    print(str(i))
    exit()
print('-1')
n, m = map(int, input().split())
constrict = [list(map(int, input().split())) for _ in range(m)]
flag = False
for i in range(10**(n-1)-1, 10**n):
    if len(str(i)) != n:
        continue
    is_correct = True
    for j, k in constrict:
        if str(i)[j-1] != str(k):
            is_correct = False
            break
    if is_correct:
        flag = True
        print(i)
        break
if not flag:
    print(-1)
n,m,*z=map(int,open(0).read().split())
for i in range(10**n):
  S=str(i)
  if len(S)==n:
    if all(S[s-1]==str(c)for s,c in zip(z[0::2],z[1::2])):
      print(S)
      quit()
print(-1)
n, m = list(map(int, input().split(' ')))
pairs = []

for i in range(m):
    pairs.append(list(map(int, input().split(' '))))

num = [-1 for i in range(n)]

for pair in pairs:
    s, c = pair

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

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

print(''.join([str(i) for i in num]))
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())

sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
for i in range(10**N):
    ans = str(i)
    if len(ans) == N and all(ans[s-1] == str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)
import sys
n,m=map(int,input().split())
l=[0]*n
o=0
for i in sys.stdin:
  s,c=map(int,i.split())
  if s==1 and c==0 and n!=1:
    o=-1
    break
  elif l[s-1]==0 or l[s-1]==c:
    l[s-1]=c
  else:
    o=-1
    break
if o==0:
  if l[0]==0 and n>1:
    l[0]=1
  o=''.join([str(i) for i in l])
print(o)
nm = list(map(int, input().split()))
sc = []
for _ in range(nm[1]):
    sc.append(list(map(int, input().split())))

for i in range(1000):
    i = str(i)
    if len(i) == nm[0]:
        for j in sc:
            if int(i[j[0]-1]) == j[1]:
                continue
            else:
                break
        else:
            print(int(i))
            exit()

print(-1)
N,M=map(int,input().split())

x=[-1]*N
ok=True
for _ in range(M):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0 and N>1) or x[s]!=-1 and x[s]!=c:
        ok=False
        break
    x[s]=c

if ok:
    ans=0
    for i in range(N):
        if x[i]==-1:
            x[i]=0 if (i>0 or N==1) else 1
        ans=ans*10+x[i]
    print(ans)
else:
    print(-1)
n,m = map(int, input().split())

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

for i in range(1000):
    
    k = str(i)
    
    if len(k) == n and all([k[s-1]==str(c) for s,c in sc]):
        print(k)
        exit()

print(-1)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
if N == 1:
    ans = 0
else:
    ans = 10 ** (N - 1)
limit = 10 ** N
while ans < limit:
    l = str(ans)
    for s, c in sc:
        if not int(l[s-1]) == c:
            break
    else:
        print(ans)
        exit()
    ans += 1
print(-1)
N,M=map(int,input().split())
ls=[list(map(int,input().split())) for _ in range(M)]
if N==1:
  b=0
  c=10
else:
  b=10**(N-1)
  c=10**N
  
for i in range(b,c):
  a=str(i)
  for j in range(M):
    if a[ls[j][0]-1]==str(ls[j][1]):
      continue
    else:
      break
  else:
    print(i)
    break
else:
  print(-1)
N, M = map(int, input().split())
ans = ['-1'] * N

if N == 1 and M == 0:
    print(0)
    exit()

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        print(-1)
        exit()

if N >= 2 and ans[0] == '0':
    print(-1)
    exit()
elif ans[0] == '-1':
    ans[0] = '1'

ans = ''.join(ans).replace('-1', '0')
print(ans)