peterverebics/CodeNet_Python_118 huggingface dataset:
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:
      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 = [list(map(int, input().split())) for _ in range(m)]

l = []
for i in sc:
    if i not in l:
        l.append(i)
l.sort()
s = [0]*n
flag = False
for i in range(len(l)):
    s[l[i][0]-1] = l[i][1]
    if l[i-1][0] == l[i][0]:
        flag = True
        break
if flag:
    print(-1)
else:
    if s[0] == 0:
        s[0] == 1
    print(s)
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
sc = []
for i in range(M):
    addList = list(map(int, input().split()))
    sc.append(addList)
a = 10**(N-1)
while a < 10**N:
    j = str(a)
    bingo = True
    for l in sc:
        if int(j[l[0]-1]) != l[1]:
            bingo = False
    if bingo:
        break
    else:
        a += 1
if a == 10**N and bingo == False:
    print(-1)
else:
    print(a)
N,M = map(int,input().split())
source = []
goal = ''
for i in range(M):
  keta,number = map(int,input().split())
  source.append((keta,number))
source.sort()
for i in range(N):
  if i < len(source):
    keta,number = source[i]
    if i == keta-1:
      goal += str(number)
    else:
      goal += '0'
  else:
    goal += '0'
k = int(goal)
if len(str(k)) == len(goal):
  print(goal)
else:
  print('-1')
n, m = map(int, input().split())

ans = ["#"]*n

for i in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == "#" or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == "#":
    ans[0] = 1
elif ans[0] == 0:
    print(-1)
    exit()

print("".join(map(str, ans)).replace("#", "0"))
n, m = list(map(int, input().split()))
ss = []
cs = []
for i in range(m):
    s, c = list(map(int, input().split()))
    ss.append(s)
    cs.append(str(c))

ans = ["_"] * n

for s, c in zip(ss, cs):
    # print(f"ans={ans}: s={s}, c={c}")
    if ans[s-1] == "_" or ans[s-1] == c:
        ans[s-1] = c
    else:
        print("-1")
        exit()

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

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

print("".join(ans).replace("_", "0"))
n,m = map(int,input().split())
d = dict()
for i in range(m):
    k,v = map(int,input().split())
    if k in d:
        if d[k] !=v:
            print(-1)
            exit()
    else:
        d[k] = v
res = ""
for i in (1,n+1):
    if i not in d:
        d[i] = 0
    res += str(d[i])
res = int(res)
if res == 0:
    print(-1)
    exit()
print(res)
#!/usr/bin/env python3
import numpy as np


N, M = [int(str) for str in input().strip().split()]
sc = set([tuple([int(str) for str in input().strip().split()]) for _ in range(M)])

sc_dict = {}
for key, value in sc:
    if key in sc_dict:
        sc_dict[key] = min(value, sc_dict[key])
    else:
        sc_dict[key] = value

if N != 1 and sc_dict.get(1, 0) == 0:
    print(-1)
else:
    num = int(''.join([str(sc_dict.get(d + 1, 0)) for d in range(N)]))
    print(num if len(str(num)) == N else -1)
# Code for C - Guess The Number
# Use input() to fetch data from STDIN
import sys
[n, m] = [int(x) for x in input().split()]
s = []
c = []

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

for x in range(1, 1000):
    a = str(x)
    if len(a) != n:
        continue

    test = all([a[i - 1] == str(j) for i, j in zip(s, c)])
    if test:
        print(x)
        sys.exit()

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

lst = [-1]*N
flag = False

for _ in range(M):
  s,c = map(int,input().split())
  if lst[s-1] > -1 and lst[s-1] != c:
    flag = True
  elif s == 1 and c== 0:
    flag = True
  else:
    lst[s-1] = c
if flag:
  print("-1")
else:
  for i in range(N):
    if i == 0 and lst[i] == -1:
      lst[i] = 1
    elif lst[i] == -1:
      lst[i] = 0
  print("".join(map(str,lst)))
import sys

N,M=list(map(int,input().split()))
num = [None] * N
for i in range(M):
    s,c=list(input().split())
    if num[int(s)-1] is not None and num[int(s)-1] != c:
        print('-1')
        sys.exit()
    else:
        num[int(s)-1] = c
if N > 1 and num[0] == '0':
    print('-1')
    sys.exit()
else:
    for i in range(N):
        if num[i] == None:
            num[i] = '0' if i > 0 else '1'
print(''.join(num))
N, M = map(int, input().split())

ans = []
neg = 0
for n in range(N):
  ans.append(-1)

for m in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == -1:
    ans[s-1] = c
  elif ans[s-1] == c:
    pass
  else:
    neg = -1
    break

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

for j in range(len(ans)):
  if ans[j] == -1:
    ans[j] = 0

if neg == -1:
  print(neg)
else:
  print("".join([str(i) for i in ans]))
n, m = map(int, input().split())
d = dict()
for i in range(m):
    s, c = map(int, input().split())
    if s==1 and c==0:
        print("-1")
        exit()
    if s in d.keys():
        print("-1")
        exit()
    d[s] = c
target = 0
all = set(range(1,n+1))
kouho = set(d.keys())
dif = all - kouho
for s, c in d.items():
    target += 10**(n-s)*c
if n in dif:
    print(100+target)
else:
    print(target)
n, m = map(int, input().split())
dct = {}
exist = True
for _ in range(m):
    s, c = map(int, input().split())
    if n != 1 and s == 1 and c == 0:
        exist = False

    if s in dct.keys():
        if dct[s] != c:
            exist = False
    else:
        dct[s] = c

if not (1 in dct.keys()):
    dct[1] = 1

if exist:
    ans = 0
    for s, c in dct.items():
        ans += c*10**(n-s)
    print(ans)
else:
    print(-1)
N, M = map(int, input().split())
from collections import defaultdict, Counter
dd=defaultdict(int)
dd_count=defaultdict(int)

for _ in range(M):
	s, c = map(int, input().split())
	#異なるものが2個ある
	if dd_count[s-1]>=1 and dd[s-1]!=c:
		exit(print(-1))
	else:
		dd[s-1]=c
		dd_count[s-1]+=1

if dd[0]==0:
	exit(print(-1))
else:
	ans=""
	for i in range(N):
		ans+=str(dd[i])
	print(int(ans))
import sys
N, M = [int(x) for x in input().split()]

digits = {x+1: 0 for x in range(N)}
for _ in range(M):
    s, c = [int(x) for x in input().split()]
    if s == 1 and c == 0:
        if N != 1:
            print(-1)
            sys.exit()
    if digits.get(s, -1) not in [c, 0]:
        print(-1)
        sys.exit()
    digits[s] = c

result = 0
n = 0
for i in sorted(digits.keys(), reverse=True):
    result += digits[i] * (10 ** n)
    n += 1
print(result)
ans=-1
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for k in range(10**(n-1),10**n):
    for i in range(m):
        if str(k)[l[i][0]-1]!=str(l[i][1]):
            break
    else: 
        ans=k
        print(ans) 
        break
if ans==-1: print(-1)
N, M = map(int, input().split())
ans = [0] * N
for i in range(M):
  s, c = map(int, input().split())
  if [s, c] == [1, 0]:
    ans = -1
    break
  if ans[s-1] in [0, c]:
    ans[s-1] = c
  else:
    ans = -1
    break
if ans != -1:

  s = ""
  for i in ans:
    s += str(i)
  ans = int(s)
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())
answer = -1

for i in range(10**(N-1),10**N):
    numstr = str(i)
    count = 0
    for j in range(M):
        if int(numstr[S[j]-1]) != C[j]:
            break
        else:
            count += 1
    if count == N:
        answer = i
        break
    else:
        answer = -1
        
print(answer)
n,m=map(int,input().split())
ans=[-1]*n
frag=1
for i in range(m):
  s,c=map(int,input().split())
  s-=1
  if ans[s]==-1:
    ans[s]=c
  elif ans[s]!=c:
    frag=0
if ans[0]==0:
  frag=0
elif ans[0]==-1:
  ans[0]=1
for i in range(1,n):
  if ans[i]==-1:
    ans[i]=0
if frag:
  print(int(''.join(map(str,ans))))
else:
  print(-1)
n,m=map(int,input().split())
ans=[0]*n

for _ in range(m):
  s,c=map(int,input().split())
  ans[s-1]=c
if n>1 and ans[0]==0:
  print(-1)
  exit()
elif n==1 and ans[0]==0:
  print(0)
  exit()
else:
  for i in ans:
    print(i,end="")
n,m = map(int,input().split())
d = dict()
for i in range(m):
    k,v = map(int,input().split())
    if k in d:
        if d[k] !=v:
            print(-1)
            exit()
    else:
        d[k] = v
res = ""
for i in (range(1,n+1)):
    if i not in d:
        d[i] = 0
    res += str(d[i])
res = int(res)
if n !=1:
    if res == 0:
        print(-1)
        exit()
print(res)
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:
        print(i)
        break
if stop:
    print(-1)
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:
    print(-1)
    exit()
  elif digits[digit] != -1 and num != digits[digit]:
    print(-1)
  else:
    digits[digit] = num
answer = 0
for i in range(1, N+1):
  if digits[i] == -1:
    if i == 1:
      answer += 1*10*(N-i)
  else:
    answer += digits[i]*10**(N-i)
print(answer)
N,M = [int(i) for i in input().rstrip().split()]
n = 1 if N > 1 else 0
C = [list(range(n,10))] + [list(range(10)) for i in range(N-1)]

for m in range(M):
    s,c = [int(i) for i in input().rstrip().split()]
    s -= 1
    if c in C[s]:
        C[s] = [c]
    else:
        print(-1)
        exit()
    print(C)
C = [str(min(c)) for c in C]
print("".join(C))
def main():
    n, m = map(int, input().split())
    l = [ (input().split()) for i in range(m)]
    l.sort(key=lambda x: x[1])
    res = ["0"]*n
    for s, c in l:
        res[int(s)-1] = c
    res = "".join(res)
    res = int(res)
    if len(str(res))==n:print(int(res))
    else:print(-1)

if __name__ == "__main__":
    main()
n, m = map(int, input().split())

tmp = ["0" for i in range(n)]
check = [0 for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  check[int(s)-1]+=1
  tmp[int(s)-1] = c
flag = True

for i in check:
  if i >= 2:
    flag = False
    
    
ans = int("".join(tmp))
if len(str(ans)) == n and flag:
  print(ans)
else:
  print(-1)
n,m=list(map(int,input().split()))
if m==0:
  print('1'+'0'*(n-1))
  exit(0)
d=[-1]*4
for _ in range(m):
  s,c=list(map(int,input().split()))
  if d[s]!=-1 and d[s]!=c:
    print(-1)
    exit(0)
  d[s]=c
ans=0
for i in range(1,n+1):
  if d[i]==-1:
    if ans==0:d[i]=1
    else:d[i]=0
  ans=10*ans+d[i]
if len(str(ans))==n:
  print(ans)
else:
  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-1), 10**n):
    isAns = True
    for s, c in sc:
        isAns *= i//(10**(n-s)) % 10 == c
    if isAns:
        ans = i
        break
print(ans)
n, m = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(m)]

ans = [0]*n

for s, c in X:
    if s==1 and c==0:
        print(-1)
        exit(0)
    if ans[s-1]:
        if ans[s-1] != c:
            print(-1)
            exit(0)
    else:
        ans[s-1] = c

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

for i in ans:
    print(i, end="")
n,m= map(int,input().split())
Nro=[0]*n
for i in range(m):
    s,c= map(int,input().split())
    Nro[s-1]=c
if (n>1) and (Nro[0]==0):
    print(-1)
else:
    print(''.join(map(str, Nro)))
N, M = map(int, input().split())
Q = [list(map(int, input().split())) for i in range(M)]


for n in range(1000):
    X = list(map(int, list(str(n))))
    for s, c in Q:
        s -= 1
        if len(X) != N:
            break

        if X[s] != c:
            break
    else:
        print(n)
        exit()

print(-1)
N,M=map(int,input().split())
ans=[0]*N
for i in range(M):
    s,c=map(int,input().split())
    ans[s-1]=c
if N!=1 and ans[0]==0:
    print(-1)
else:
    l=[str(a) for a in ans]
    print("".join(l))
n,m = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(m):
  t,s = map(int,input().split())
  if (a[t-1] == 0 and b[t-1] == 0) or (a[t-1] == s):
    a[t-1] = s
  else:
    print('-1')
    exit()
  if s == 0 :
    b[t-1] = 1

tmp = ''
if sum(a) == 0:
  print('-1')
  exit()
for i in range(n):
  tmp += str(a[i])
print(int(tmp))
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for _ in range(M)]
for x in range(10 ** N):
  f = 1
  for i in range(M):
    s = str(x)
    y, c = t[i]
    if len(s) < y or (len(s) < N):
      f = 0
      break
    if int(s[y - 1]) != c:
      f = 0
      break
  if f:
    print(x)
    exit(0)
print(-1)
N,M= map(int,input().split())
s=[]
c=[]
ans=-1
for i in range(M):
    s_i,c_i=input().split()
    s.append(int(s_i))
    c.append(c_i)
for i in reversed(range(int("1"+"0"*(N-1)),int("9"*N)+1)):
    ans_bool=True
    for j in range(M):
        ans_bool=ans_bool and str(i)[s[j]-1]==str(c[j])
    if ans_bool:
        ans=i
        
print(ans)
n, m = map(int, input().split())
numbers = [0]*n
existence = False



for _ in range(m):
    s, c = map(int, input().split())
    if c > numbers[s-1]:
        numbers[s-1] = c
    if s == 1:
        if c != 0 or n == 1:
            existence = True

if existence:
    print(*numbers, sep='')
else:
    print(-1)
n, m = map(int, input().split())
array = [None] * n
for i in range(m):
  keta, num = map(int, input().split())
  if n >= 2 and keta == 1 and num == 0:
    print(-1)
    break
  if array[keta-1] != None and array[keta-1] != num:
    print(-1)
    break
  array[keta-1] = num
  
  if i == m-1:
    ans = 0
    for k in range(n):
      if array[k] != None:
        ans += 10**(n-1-k)*array[k]
    print(ans)
#22 C - Guess The Number
N,M = map(int,input().split())

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

ans = [0]*N
for i, j in sc:
    if ans[i-1] != 0:
        result = -1
        break
    ans[i-1] = j
else:
    if ans[0] == 0:
        ans[0] = 1
    ans = [str(k) for k in ans]
    result = ''.join(ans)
if (1,0) in set(sc):
    result = -1
if N == 1 and M == 1 and sc == [(1,0)]:
    result = 0
print(result)
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    inf = float('inf')
    number = [inf] * n

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        number[si] = min(number[si], ci)

    for index, num in enumerate(number):
        if num == inf:
            number[index] = 0

    candidate = ''.join(map(str, number))

    if len(str(int(candidate))) == len(candidate):
        print(candidate)
    else:
        print(-1)


if __name__ == '__main__':
    main()
n,m = map(int,input().split())
t = [0 for i in range(n)]
b = ""
a = True
for i in range(m):
    s,c = map(int,input().split())
    if t[s-1] == 0 or t[s-1] == c:
        t[s-1] = c
    else:
        a=False
for i in range(n):
    b += str(t[i])
if a and b[0]!='0':
    print(b)
else:
    print(-1)
n, m = map(int, input().split())
scList = [list(map(int, input().split())) for _ in range(m)]
num = ["-" for _ in range(n)]
flag = True
for i in range(m):
    s = scList[i][0] - 1
    c = scList[i][1]
    if (num[s] != "-" and num[s] != str(c)) or (s == 0 and c == 0):
        flag = False
        break
    num[s] = str(c)
if not flag:
    print("-1")
else:
    ans = "".join(num)
    ans = ans.replace("-", "0")
    if ans[0] == "0":
        ans = "1" + ans[1:]
    print(ans)
N, M=map(int, input().split())

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

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0:
  ans=False
    
if ans:
  for i in range(N):
    if num[i]=="a":
      print(1, end="")
    else:
      print(num[i], end="")
else:
  print(-1)
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:
		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())
list=[list(map(int,input().split())) for _ in range(m)]
flag=False
ans=['10']*n
for i in range(m):
  if (list[i][0]==n and list[i][1]!=0) or (n==1 and list[i][0]==n and list[i][1]==0):
    flag=True
  ans[list[i][0]-1]=str(min(int(ans[list[i][0]-1]),list[i][1]))
if flag==True:
  for j in range(n):
    if ans[j]=='10':
      ans[j]='0'
  print(''.join(ans))
else:
  print('-1')
n,m=map(int,input().split())
d=[0]*(n+1)
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        if n==1:
            pass
        else:
            print(-1)
            exit()
            
    if d[s]==c:
        continue
    elif d[s]!=c and d[s]==0:
        d[s]=c
    else:
        print(-1)
        exit()
print("".join(list(map(str,d[1:]))))
N,M = list(map(int,input().split()))
SC = [0]*(N+1)
for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    print(-1)
    exit()
  if SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()
    else:
      SC[sc[0]] = sc[1]

if SC[1]==0:
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
guess=["0"]*N
for i in sc:
  guess[i[0]-1]=i[1] 
if guess[0]=="0":
  print("-1")
else:
  for i in guess:
    print(i,end="")
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)==(0,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())

hints = []
for _ in range(M):
  a, b = map(int, input().split())
  hints.append((a, b))
  
def solve(n, hints):
  for i in range(10 ** (N + 1)):
    s = str(i)
    if all(len(s) == N and s[hint[0] - 1] == str(hint[1]) for hint in hints):
      return i
  return -1
      
print(solve(N, hints))
from collections import defaultdict

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

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

flag = True

num = {}

for s, c in sc:
    if s == 1 and c == 0:
        flag = False
        break
    elif num.get(s) == None:
        num[s] = c
    else:
        if num.get(s) != c:
            flag = False
            break

a = -1

if flag:
    a = 0
    for k, v in num.items():
        a += v * (10**(n-k))

print(a)
n,m = map(int,input().split())
sc = [tuple(map(int,input().split())) for i in range(m)]
l = [0]*n
ans = -1
for t in sc:
    l[t[0]-1] = t[1]
if l[0]==0:
    print(-1)
else:
    print("".join([str(s) for s in l]))
import sys


def LI():
    return list(map(int, input().split()))


N, M = LI()
ans = [-1]*N
for _ in range(M):
    a, b = LI()
    if ans[a-1] == b or ans[a-1] == -1:
        ans[a-1] = b
    else:
        print(-1)
        sys.exit()
if ans[0] == -1:
    ans[0] = 1
S = ""
for i in range(N):
    if ans[i] == -1:
        ans[i] = 0
    S += str(ans[i])
if S == "0"*N:
    S = -1
print(S)
n,m=map(int, input().split())
r = []
flg = []

for i in range(n):
    r.append(str(0))
    flg.append(0)

for i in range(m):
    s,c = map(int, input().split())
    if flg == 1 and int(r[s-1]) < c:
        r[s-1] = r[s-1]
    else:
        r[s-1] = str(c)
        flg[s-1] = 1
    
if n == 1 and r[0] == '0':
    print(0)
elif r[0] == '0':
    print('-1')
else:
    print(''.join(r))
import sys
N,M=map(int,input().split())
listSC=[]  
for k in range(M):
  s,c=map(int,input().split())
  listSC+=[[s,c]]
MAX=0  
if N==1:
  for s,c in listSC:
    MAX==(MAX,c)
  if MAX==0:
    print(0)
    sys.exit()    
for i in range(10**(N-1),10**N):
  A=list(str(i))
  for k in range(M):
    if A[listSC[k][0]-1]!=str(listSC[k][1]):
      break
    if k==M-1:
      ans=i
      print(ans)
      sys.exit()
  if i==10**N-1:
    print(-1)
N, M = map(int, input().split())

flag = 0
x = [-1] * N
for m in range(M):
  s, c = map(int, input().split())
  if (x[s-1] != -1) & (x[s-1] != c):
    #print("{} {}".format(s,c))
    flag = 1
    break
  else:
    x[s-1] = c
#print(x)
    
ans = 0
for n in range(N):
  if x[n] != -1:
    ans += 10**(N-n-1) * x[n]
#print(ans)

if (N == 1) & (M > 0):
  print(ans)

elif (ans >= 10**(N-1)) & (flag == 0):
  print(ans)
else:
  print(-1)
N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    s, c = map(int, input().split())
    d = a[s-1]
    if d != 0:
        a[s-1] = min(c, d)
    else:
        a[s-1] = c
if a[0] != 0:
    print(*a, sep="") 
else:
    print("-1")
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
  if zero[order]=="0" or zero[order]==li[i][1]:
    zero[order]=li[i][1]
  else:
    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)
#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 and len(ans)<3:
    for i in ans:
        print(i,end="")
elif ans[0]==0:
    print(-1)
else:
    for i in ans:
        print(i,end="")
#print(ans)
n,m=[int(i) for i in input().split()]
s=['*']*n
flag=0
for i in range(m):
    a,b=[int(i) for i in input().split()]
    if(s[a-1]=='*'):
        s[a-1]=str(b)
    else:
        if(s[a-1]!=str(b)):
            flag=1
for i in range(0,len(s)):
    if(s[i]=='*'):
        s[i]='0'
e=''
for i in range(0,len(s)):
    e=e+s[i]
e=int(e)
if(len(str(e))!=n or flag==1):
    print(-1)
else:
    print(e)
N, M = list(map(int,input().split()))
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int,input().split()))
    s[i] -= 1

err = False

digit = [0]*N
digit_bool = [False]*N

for i in range(M):
    if digit_bool[s[i]]:
        if digit[s[i]] != c[i]:
            err = True
    else:
        digit[s[i]] = c[i]
        digit_bool[s[i]] = True

if digit[0] == 0:
    err = True

if err:
    print('-1')
else:
    print(''.join(list(map(str,digit))))
N, M = map(int, input().split())
arr = []
ans = [0] * N
for i in range(M):
    s, c = map(int, input().split())
    print(s, c)
    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit(0)
    if s in arr and ans[s-1] != c:
        print(-1)
        exit(0)
    arr.append(s)
    ans[s-1] = c
print("".join([str(i) for i in ans]))
N, M = map(int, input().split())
sc = [list(map(int, input().split()))for i in range(M)]
ans="-1"
tmp=0
for i in range(0,1000):
	s = str('{:0=3}'.format(i))
	for j in range(M):
		if sc[j][0]==1 and sc[j][1] == 0:
			print(-1)
			exit()
		if s[len(s)-N+sc[j][0]-1]!=str(sc[j][1]):
			break
	else:
		if s[0]=="0":
			s=str(int(s)+100)
		ans=s
		break
print(ans)
n,m=map(int,input().split())
a=[-1]*n
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if a[s]==-1 or a[s]==c:
        a[s]=c
    else:
        print(-1)
        exit()
if n==1 and a[0]==0:
    print(0)
    exit()
if a[0]==-1:
    a[0]=1
if a[0]==0:  
    print(-1)
    exit()
b=""
for i in a:
    if i==-1:
        b+="0"
    else:
        b+=str(i)
print(b)
n, m = map(int, input().split())
l = [0]*n

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

if l == -1:
    print(l)
else:
    print("".join(map(str, l)))
n, m = map(int, input().split())
ans = [0] * n

for _ in range(m):
    i, kk = map(int, input().split())
    if ans[i-1] == 0:
        ans[i-1] = kk

if ans[0] == 0:
    print(-1)
else:
    ans = [str(s) for s in ans]
    print(''.join(ans))