peterverebics/CodeNet_Python_118 huggingface dataset:
#!/usr/bin/env python3

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())


start = 10 ** (N-1)
end = 10 ** N

ans = -1
for i in range(start, end):
    si = str(i)
    f = True
    for j in range(M):
        if si[s[j]-1] != str(c[j]):
            f = False
            break
    if f:
        ans = i
        break

    
print(ans)
N,M = list(map(int,input().split()))
from collections import defaultdict
q = defaultdict(set)
for i in range(M):
  s,c = list(map(int,input().split()))
  q[s] |= {c}
  
for i in range(10**N):
  for key,value in q.items():
    v = list(value)[0]
    if len(value) > 1 :
      break
    elif len(str(i)) < N or str(i)[key-1] != str(v):
      # だめなとき
      break
  else:
    print(i)
    break
else:
  print(-1)
n, m = map(int, input().split())
lis = [list(map(int, input().split())) for _ in range(m)]
ans = -1
i = 10**(n-1)
while (ans == -1) & (i < 10**n):
    s = 0
    for j in lis:
        if str(i)[j[0]-1] == str(j[1]):
            s += 1
        else:
            s += 0
    if s == m:
        ans = i
    else:
        i += 1
print(ans)
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
a=0
for i in range(M):
	s[i],c[i]=map(int,input().split())
ans=-1
if M==0:
	ans=1*(10**(N-1))
	print(ans)
	exit()
if max(s)>N:
	print(ans)
	exit()
for j in range(0,1000):
	value=str(j)
	if len(value)==N:
		for S,C in zip(s,c):
			if int(value[S-1])==C:
				a+=1
		if a==M:
			ans=int(j)
			break
		else:
			a=0
	else:
		continue
print(ans)
N,M = map(int,input().rstrip().split(" "))
ans = 0
n = [-1 for i in range(N)]
for i in range(M):
  s,c = map(int,input().rstrip().split(" "))
  s -= 1
  if n[s] == -1 or n[s] == c:
    n[s] = c
  else:
    ans = -1
if N != 1 and n[0] == 0:
  ans = -1

if ans == -1:
  print(-1)
elif M == 0:
  print(0)
else:
  for i in range(N):
    if n[i] == -1:
      if i == 0:
        ans = ans + 10 ** (N -1)
    else:
      ans += 10 ** (N - i -1) * n[i]
  print(ans)
vs = input().split(' ')
N = int(vs[0])
M = int(vs[1])
valueMap = [0 for i in range(N)]

for i in range(M):
  vs = input().split(' ')
  t_i = int(vs[0]) - 1
  t_v = int(vs[1])
  
  if (valueMap[t_i] == 0 or valueMap[t_i] > t_v):
    valueMap[t_i] = t_v
  
print(valueMap)
if (valueMap[0] == 0):
  print(-1)
else:
  print("".join(map(str, valueMap)))
import sys
input = sys.stdin.readline


n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * n
cnt = [-1] * n
tmp = 0

for i in range(m):
    if cnt[sc[i][0] - 1] == -1:
        ans[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] = 1
    elif ans[sc[i][0] - 1] != sc[i][1]:
        tmp ==1

if (tmp==1) | (ans[0]==0):
    print(-1)
else:
    print(*ans, sep='')
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, s = map(int, input().split())
    s = str(s)
    if (l[a-1] and l[a-1] != s) or (a==1 and s=="0"):
        l = [-1]
        break
    else:
        l[a-1] = s

num = "".join(map(str, l))

if num[0] == "0":
    print("1" + num[1:])
else:
    print(num)
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:
    a[0] = 1
  print(''.join(map(str, a)))
n,m = map(int,input().split())
s = []
c = []

ans = ['0' for i in range(n)]
f = True
for i in range(m):
    ss,cc = map(int,input().split())
    for l,o in enumerate(s):
        if s[l] == ss and c[l] != cc:
            f = False
    if ss == 1 and cc == 0:
        f = False
    s.append(ss)
    c.append(cc)

for i,o in enumerate(s):
    ans[o-1] = str(c[i])

if ans[0] == 0:
    f = False
if f == False:
    print('-1')
else:
    print(''.join(ans))
N,M=map(int,input().split())
n=['0']*N
a=0
for i in range(M):
    s,c=map(str,input().split())
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        a=1
    if s=='1' and c=='0' and N!=1:
        a=1
    n[int(s)-1]=c
if n[0]=='0':
    n[0]='1'
if a==0:
    print(''.join(n))
else:
    print(-1)
N, M = map(int,input().split())
answer = [-1]*N
ae = 0
  

for i in range(M):
  s,c = map(int,input().split())
  if answer[-s] == -1:
    answer[-s] = c
  elif answer[-s] != -1 and answer[-s] != c:
    print(-1)
    ae = 1
    break
for i in range(N):
  if answer[i] == -1:
    if i == 0 and N > 1:
      answer[i] = 1
    else:
      answer[i] = 0
if ae == 0 and answer[N-1] == 0 and N != 1:
  print(-1)
  ae = 1
elif ae == 0:
  for i in range(N):
    print(answer[-(i+1)],end='')
n, m = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(set)
for i in range(m):
  s, c = list(map(int, input().split()))
  d[s].add(c)

s = ""
for i in range(1, n+1):
  if i == 1 and d[i] == set():
    s += "1"
  elif i == 1 and list(d[i])[0] == 0:
    print(-1)
    exit()
  elif d[i] == set():
    s += "0"
  elif len(d[i]) >= 2:
    print(-1)
    exit()
  else:
    s += str(list(d[i])[0])

print(s)
N, M = map(int, input().split())
s = [input().split() for i in range(M)]
fl = 1

ans = -1
for num in range(1000):
  if fl == 0:
    break
  else:
    if len(str(num)) != N:
      continue
    for i in range(M):
        if int(str(num)[int(s[i][0])-1]) != int(s[i][1]):
          break
        elif i == M-1:
          ans = num
          fl = 0
print(ans)
import sys

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

cond = list(list(map(int, input().split())) for i in range(m))

num = [0]*n

for i in range(m):
    digit = cond[i][0] - 1
    a = cond[i][1]
    if num[digit] == 0 or num[digit] == a:
        num[digit] = a
    else:
        print(-1)
        sys.exit()
        
if num[0] == 0:
    print(-1)
    sys.exit()

number = 0
for i in range(n):
    d = n - i - 1
    number += pow(10,d)*num[i]
    
print(number)
n, m = map(int,input().split())
dig = [0 for i in range(n)]
ans = ''
flag = 0
for i in range(m):
    s,c = map(int,input().split())
    dig[(s-1)] = c
for i in range(n):
    if i == 0:
        if dig[i] != 0:

            ans += str(dig[i])
        else:
            flag = 1
            continue
    else:
        ans += str(dig[i])
if flag == 0:
    print(ans)
elif flag ==1:
    print('-1')
N,M = list(map(int, input().split()))
S = set()
for _ in range(M):
  S.add(tuple(map(int, input().split())))
  
A = [1] + [0] * (N-1)
CH = [False] * N

for l in S:
  idx, num = l[0] - 1, l[1]
  if CH[idx]:
    print(-1)
    exit(0)
  if N > 1 and idx == 0 and num == 0:
    print(-1)
    exit(0)
  CH[idx] = True
  A[idx] = num
  
if len(S) == 0 and N == 1:
  print(1)
else:
  print("".join(list(map(str,A))))
n,m = input().split()
m = int(m)
s =  [list(map(int,input().split())) for i in range(m)]
#print(s)
brk =0
n = int(n)
nl = [0]*n
chk = [0]*n
for i in s:
    if chk[i[0]-1] >0 and nl[i[0]-1] != i[1]:
        brk = 1
        break
    else:
        nl[i[0]-1] = i[1]
        chk[i[0]-1] += 1

if brk == 1: print("-1")
elif nl[0] == 0: print("-1")
else:
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))

  print(fn)
import sys

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

for a in ar:
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    ans[0] = 1

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

num = []
for i in range(N) :
  num.append([0])

sc = []
for i in range(M) :
  sc.append(list(map(int, input().split()))) 

ans = ""

for n in sc :
  if n[1] not in num[n[0]-1] :
    num[n[0]-1].append(n[1])

for m in num :
  if len(m) >= 3 :
    print('-1')
    sys.exit()

if len(num[0]) == 1 :
  print('-1')
  sys.exit()
else :
  for l in range(N) :
    ans = ans + str(max(num[l]))

print(ans)
n, m = map(int, input().split(' '))
sayi = '*'
for i in range(n-1):
  sayi += '*'
for i in range(m):
  s, t = map(int, input().split(' '))
  if s == 1 and t == 0:
    print(-1)
    break
  if sayi[s-1] == '*' or sayi[s-1] == str(t):
    sayi[s-1] == str(t)
  else:
    print(-1)
    break
for i in range(len(sayi)):
  if sayi[i] == '*':
    if i == 0:
      sayi[i] == '1'
    else:
      sayi[i] == '0'
print(sayi)
    
print()
import sys
import numpy as np
n,m = map(int, input().split())
s = list()
c = list()
for i in range(m):
    a,b = map(int, input().split())
    if not a in s:
        s.append(a)
        c.append(b)
    else:
        c[s.index(a)] == min(c[s.index(a)],b)
if not 1 in s:
    print('-1')
    sys.exit()
result = 0
for i,v in zip(s,c):
    result += (10**(n - i))*v
if result >= 0:
    print(str(result))
else:
    print('-1')
n,m = map(int,input().split())

o=[10]*3

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

if o[0]==0:
  print("-1")
  exit()
if o[0]==10:
  o[0]=1

for i in range(0,3):
  if o[i]==10:
    print(0,end="")
  else:
    print(o[i],end="")
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
for i in range(10**(n-1),10**n):
    stri=str(i+1)
    c=0
    for j in range(m):
        if stri[sc[j][0]-1]==str(sc[j][1]):
            c+=1
    if c==m:
        print(i+1)
        break
    elif i==10**n-1:
        print(-1)
        break
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:
    if str_i[s-1] == c:
      cnt &= str_i[s-1] == str(c)
  if chk:
    print(i)
    exit()

  print(-1)
import sys
N,M=map(int,input().split())
A=[-1 for _ in range(N)]

for i in range(M):
  s,c=map(int,input().split())
  if A[s-1]!=-1 and A[s-1]!=c:
    print(-1)
    sys.exit()
    
  else:
    A[s-1]=c
for i in range(N):
  if A[i]==-1:
    A[i]=0
if A[0]==0:
  print(-1)
else:
  ans=0
  for i in range(N):
    ans=ans+A[i]*10**(N-i-1)
  print(int(ans))
n, m = list(map(int, input().split()))

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

ans = [0 for _ in range(n)]
check = [False for _ in range(n)]

flag = 0

for i, j in a:
    if check[i-1] == 0 or ans[i-1] == j:
        ans[i-1] = j
        check[i-1] = True
    else:
        flag = 1
       
if check[0] == False and ans[0] == 0:
    ans[0] = 1

c = ""
for k in ans:
    c+=str(k)

if flag == 1 or len(str(int(c))) != n:
    print(-1)
else:
    print(c)
vs = input().split(' ')
N = int(vs[0])
M = int(vs[1])
valueMap = [0 for i in range(N)]

for i in range(M):
  vs = input().split(' ')
  t_i = int(vs[0]) - 1
  t_v = int(vs[1])
  
  if (valueMap[t_i] > t_v):
    valueMap[t_i] = t_v
  
if (valueMap[0] == 0):
  print(-1)
else:
  print("".join(map(str, valueMap)))
n,m=map(int,input().split())
ans = [11]*n
for i in range(m):
  s,c=map(int,input().split())
  if ans[s-1] > c:
    ans[s-1]=c

if ans[0]==11:
  print(-1)
else:
  for i in range (len(ans)):
    if ans[i]==11:
      ans[i] = 0
  for i in ans:
    print(i,end='')
N, M = [int(i) for i in input().split()]
d = [0]*N
m = [0]*N
d[0] = 1
for i in range(M):
    idx, v = [int(i) for i in input().split()]
    idx-=1
    if idx==0:
        if v==0:
            print(-1)
            quit()
    if m[idx]==1:
        if d[idx]!=v:
            print(-1)
            quit()
    d[idx] = v
    m[idx] = 1
print(*d, sep='')
import sys
import math
N, M = map(int, input().split())
NUMS = [list(map(int, input().split())) for _ in range(M)]

for n in range(10 ** (N - 1), 10 ** (N)):
    res = 0
    for s, c in NUMS:
        if str(n)[s - 1] == str(c):
            res += 1
    
    if res == M:
        print(n)
        sys.exit()
        
print("-1")
n, m = list(map(int, input().split()))
sc = {}
for i in range(m):
    si, ci = list(map(int, input().split()))
    if (si in sc and sc[si] !=ci) or (si == 1 and ci == 0):
        print(-1)
        exit()
    sc[si] = ci

d = [1] + [0] * (n-1)

for si, ci in sc.items():
    d[si-1] = ci

s = ""
for c in d:
    s += str(c)
print(s)
N, M = map(int,input().split())

ans = [None] * N
flag = 1
for i in range(M):
    s,c = map(int,input().split())

    if (c == 0 and s < N) or (ans[s-1] and ans[s-1] != c):
        flag = 0
        break
    ans[s-1] = c

for i in range(N):
    if not ans[i]:
        ans[i] = 0

if flag:
    print("".join([str(x) for x in ans]))
else:
    print(-1)
n,m=map(int,input().split())
d={}
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if s==0 and c==0:
        print(-1)
        exit()
    if s in d and d[s]!=c:
        print(-1)
        exit()
    else:
        d[s]=c
l=["0"]*n
for i,k in d.items():
    l[i]=str(k)
if l[0]=="0":
    l[0]="1"
print("".join(l))
import sys
N, M = map(int, input().split())
s = {}
ans = 0

for _ in range(M):
    si, ci = map(int, input().split())
    if si in s.keys():
        if ci != s[si]:
            print(-1)
            sys.exit()
        else:
            continue
    s[si] = ci
    ans += ci * 10**(N-si)
print(ans if ans > 0 else -1)
n,m = map(int,input().split())
s=[0]*m
c=[0]*m
ans=[]
judge=False
for i in range(m):
    s[i],c[i]=map(int,input().split())
for j in range(10**(n-1),10**n):
    j=str(j)
    for l in range(m):
        if int(j[s[l]-1])==c[l]:
            pass
        else:
            break
    else:
        ans.append(int(j))
        judge=True
if judge:
    print(min(ans))
else:
    print('-1')
import math

N, M = map(int, input().split())
num = [-1] * N

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

ans = 0

for i in range(N):
    if num[i] == -1:
        if i == 0:
            num[i] = 1
        else:
            num[i] = 0
    ans += int(num[i] * math.pow(10, N - i - 1))

if len(str(ans)) != N:
    print(-1)
else:
    print(ans)
N, M = map(int, input().split())

d = {}
flag = True

for i in range(M):
    s, c = map(int, input().split())
    if s in d.keys() and d[s] != c:
        flag = False
    d[s] = c

if 1 not in d.keys():
    d[1] = 1
elif N > 1 and d[1] == 0:
    flag = False

if M != 0 and max(d.keys()) > N:
    flag = False

if flag:
    res = 0
    for s, c in d.items():
        res += c * 10 ** (N - s)
    print(res)
else:
    print("-1")
n,m = map(int,input().split())
ans = []
li = []

for i in range(m):
    s,c = map(int,input().split())
    li.append([s,c])

for i in range(10**(n-1),10**n):
    buf = str(i)
    flag = True
    for j in range(len(li)):
        if buf[li[j][0]-1] != str(li[j][1]):
            flag = False
    if flag:
        ans.append(buf)
        flag = True

ans.sort()
if ans:
    print(ans[0])
else:
    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), 10**n):
    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=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=["X"]*n
for s,c in sc:
  if ans[s-1]=="X" or ans[s-1]==str(c):
    ans[s-1]=str(c)
  else:
    print(-1)
    exit()
if ans[0]=="X":
  ans[0]="1"
if ans[0]=="0":
  print(-1)
  exit()
ans="".join(ans)
ans=ans.replace("X", "0")
print(int(ans))
def solve(string):
    n, m, *sc = map(int, string.split())
    v = [0] * n
    for s, c in zip(*[iter(sc)] * 2):
        if (v[s - 1] > 0 and v[s - 1] != c) or (s == 1 and c == 0):
            return "-1"
        v[s - 1] = c
    if v[0] == 0:
        v[0] += 1
    return "".join(map(str, v))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
N,M=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(M)]
zero=["0"]*N
for i in range(M):
  order=li[i][0]-1
  try:
    zero[order]=li[i][1]
  except:
    print(-1)
    exit()
a=[str(s) for s in zero]
a2="".join(a)
a3=int(a2)
a4=str(a3)
if len(a2)!=len(a4):
  print(-1)
  exit()
print(a2)
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)
loop = True

for i in range(0, 10 ** n):
    string = str(i)
    if len(string) != n:
        continue
    for j in range(m):
        if string[s[j] - 1] != str(c[j]):
            break
        if j == m - 1:
            print(string)
            loop = False
    if loop == False:
        break

if loop == True:
    print('-1')
cnt = 0
po = 1
n,m = map(int,input().split())
ans = [0 for i in range(n)]
if(m == 0):
  print(0)
  exit()
sc = [list(map(int,input().split())) for i in range(m)]
for i in sc:
  if((ans[i[0]-1] != 0 and ans[i[0]-1] != i[1] ) or (i[0] == 1 and i[1] == 0 and n != 1)):
    print(-1)
    exit()
  else:	
    ans[i[0]-1] = i[1]
if(ans[0] == 0 and n != 1):
  ans[0] = 1
for i in range(n-1,-1,-1):
  cnt += ans[i] * po
  po *= 10
print(cnt)
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, M = getInput()
ret = [int(0) for i in range(N+1)]
ret[0] = -1
flg = False

for i in range(M):
    S, C = getInput()
    if not ret[S] == 0:
        if ret[S] == C:
            continue
        else:
            flg = True
    ret[S] = C

ret.pop(0)
if ret[0] == 0:
    flg = True

print('-1') if flg else print(''.join([str(i) for i in ret]))
N, M = map(int, input().split())
lis = [0]*N
SC = []
ERROR = False
for _ in range(M):
  sc = list(map(int, input().split()))
  SC.append(sc)
for i in range(len(SC)-1):
  for j in range(i+1,len(SC)):
    if SC[i][0] == SC[j][0] and SC[i][1] != SC[j][1]:
      ERROR = True
if ERROR:
  print(-1)
else:
  output = ''
  for i in range(M):
    lis[SC[i][0]-1] = SC[i][1]
  if N > 1 and lis[0] == 0:
    print(-1)
  else:
    for i in range(N):
      output += str(lis[i])
    print(output)
n,m = map(int,input().split())
dic = {}
sum = 0
for i in range(m):
  s,c = map(int,input().split())
  if s in dic and dic[s] != c:
    print(-1)
    break
  dic[s] = c
else:
  if 1 in dic and dic[1] == 0:
    print(-1)
  elif 1 not in dic:
    dic[1] = 1
    for i in dic:
      sum += dic[i]*((10)**(n-i))
    print(sum)
  else:
    for i in dic:
      sum += dic[i]*((10)**(n-i))
    print(sum)
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-1),10**n):
    st=str(ans)
    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())
a = [10 for x in range(n)]
for _ in range(m):
    s, c = map(int, input().split())
    if c < a[s-1]:
        a[s-1] = c

strn = ""
if a[0] == 10:
    print(-1)
else:
    if a[0] == 0 and len(a) != 1:
        print(-1)
    else:
        for x in a:
            strn += str(0) if x==10 else str(x)
        print(int(strn))
        
print("\n")
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
print(sc)
for i in range(10**n):
  i2=str(i)
  print(i2)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      exit()
print(-1)
n,m = map(int,input().split())
ans = [99]*n
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 99 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0 and n != 1:
    print(-1)
    exit()
if ans[0] == 99:
    ans[0] = 1
for i in range(n):
    if ans[i] == 99:
        ans[i] = 0


print("".join([str(i) for i in ans]))
import sys
ANS = []
N, M = map(int, input().split())
for j in range(N):
  ANS.append(0)
for i in range(M):
  s, c = map(int, input().split())
  ANS[s-1] = c
 
if ANS[0] == 0:
  print(-1)
  sys.exit()
 
NEW = 0
for i in range(N):
  NEW += ANS[-i-1] * (10**(i+1))
 
print(NEW)
n,m=map(int,input().split())
ans=[]
check=True
for i in range(n):
  ans.append('0')
for i in range(m):
  s,c=map(str,input().split())
  if ans[int(s)-1]=='0':
    ans[int(s)-1]=c
    
  else:

    if ans[int(s)-1]!=c:
      check=False
  if s=='1' and c=='0':
    check=False

if ans[0]=='0':
  ans[0]='1'

chu=''.join(ans)
if check:
  print(chu)
else:
  print(-1)
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

D=[-1]*N
ans=True

for s,c in S:
    if D[s-1] == -1:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False

if D[0]==0 and 1<N: ans=False
if D[0]==-1: D[0]=1

for i in range(N):
    if D[i]==-1: D[i]=0 
     
print(''.join(map(str,D)) if ans else -1)
import sys
n, m = list(map(int, input().split()))
res = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]

for r in res:
	if ans[r[0] - 1] >= 0:
		if ans[r[0] - 1] != r[1]:
			print(-1)
			sys.exit()
	ans[r[0] - 1] = r[1]

flag = 0
for i in range(n):
	if ans[i] == -1:
		if flag:
			ans[i] = 0
		else:
			ans[i] = 1
	if i == 0 and ans[i] == 0:
		print(-1)
		sys.exit()
	else:
		flag = 1


print("".join([str(a) for a in ans]))
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
a=0
for i in range(M):
	s[i],c[i]=map(int,input().split())
ans=-1
for j in range(1,1000):
	value=str(j)
	if len(value)==N:
		for S,C in zip(s,c):
			if int(value[S-1])==C:
				a+=1
		if a==M:
			ans=int(j)
			break
		else:
			a=0
	else:
		continue
print(ans)
#graph implementation
import math
n,m=map(int,input().split())
ans=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==0:
            ans[s-1]=c
    else:
        if ans[s-1]>=c and c>0:
            ans[s-1]=c
if ans[0]==0:
    print(-1)
else:
    for i in ans:
        print(i,end="")
#print(ans)
N,M=map(int,input().split())
ans=[-1]*(N+1)
for i in range(M):
    s,c=map(int,input().split())
    if ans[s]==c :
        ans[s]=c
    elif ans[s]==-1 :
        ans[s]==c
    else:
        print('-1')
        exit()
if N>1 and ans[1]==-1:
    print('-1')
    exit()
else:
    pass
# FA=ans[1:]
# FA=''.join(FA)
for a in ans:
    if a==-1:
        a=0
FA=0
for j in range(len(ans)-1):
    FA+=10**j *ans[(-1)*(j+1)]
print(FA)
n,m= map(int,input().split())
res=[-1]*n
for _ in range(m):
    s,c = map(int,input().split())
    if res[s-1] != -1 and res[s-1] != c:
        print(-1)
        exit()
    else:
        res[s-1] = c

if res[0] == -1 and n != 1:
    res[0] = 1
res.reverse()
out = 0
for i in range(len(res)):
    if res[i]!=-1:
        out += res[i]*10**i
    

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

r = [9 , 9, 9]

S = []

for _ in range(m):
    s, c = map(int,input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if r[s - 1] > c:
        r[s - 1] = c
    S.append(s)

for j in range(1, n + 1):
    if j not in S:
        r[j - 1] = 0


if r[0] == 0 and n == 3:
    print(-1)
    exit()

if r[1] == 0 and n == 2:
    print(-1)
    exit()

for a in range(n):
    print(r[a], end="")
print()
import sys

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

mylist = [0 for _ in range(N)]

for _ in range(M):
    s, c = list(map(int, input().split()))
    mylist[s - 1] = c

if mylist[0] == 0:
    print("-1")
    sys.exit()

ans = 0
for i in range(N):
    ans = ans + mylist[N - 1 - i] * 10 ** i
    
print(ans)
n,m=map(int,input().split())
a=[0]*n
count=0

for i in range(m):
  s,c=map(int,input().split())
  if a[s-1]==0 or c:
    a[s-1]=c
  else:
    print("-1")
    exit()
    
if a[0]==0 and n!=1:
      print("-1")
      exit()
      
for i in range(len(a)):
  print(a[i],end='')
#C
n,m=map(int,input().split())
a_list=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    a_list[s-1]=c

if n==1 and a_list[0]==0:
    print('0')
elif a_list[0]==0:
    print('-1')
else:
    map = map(str, a_list)
    print(''.join(map))
N, M = map(int, input().split())
A = [float('inf') for _ in range(N)]

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

    #A[s] = min(A[s], c)
    A[s] = c

for i in range(N):
    if A[i] == float('inf'):
        A[i] = 0
    A[i] = str(A[i]) 

#print(A)
ans = int(''.join(A))

if len(str(ans)) == N: print(ans)
else: print(-1)