CodeEff/ECCO huggingface dataset:
# Original solution
n, m = list(map(int, input().split()))
sc = []
for _ in range(m):
    s_, c_ = list(map(int, input().split()))
    sc.append([s_-1, c_])
ans = [-1 for _ in range(n)]
for s, c in sc:
    if s == 0 and c == 0:
        if n != 1:
            print((-1))
            exit()
    if ans[s] is -1: ans[s] = c
    elif ans[s] is not None and ans[s] != c:
        print((-1))
        exit()
for i in range(n):
    if ans[i] == -1:
        if i == 0:
            if n == 1: ans[i] = 0
            else: ans[i] = 1
        else:
            ans[i] = 0
print(("".join(map(str, ans))))

# Optimized solution
n, m = list(map(int, input().split()))
dic = {i: -1 for i in range(1, n + 1)}
for _ in range(m):
    s_, c_ = list(map(int, input().split()))
    if dic[s_] == -1:
        dic[s_] = c_
    else:
        if dic[s_] != c_:
            print((-1))
            exit()
if n == 1:
    if dic[1] == -1:
        print((0))
    else:
        print((dic[1]))
    exit()
if dic[1] == 0:
    print((-1))
    exit()
res = ""
keys = list(dic.keys())
keys.sort()
for k in keys:
    if dic[k] == -1:
        if k == 1:
            res += "1"
        else:
            res += "0"
    else:
        res += str(dic[k])
print(res)
# Original solution
check = 0
check2 = 0
kensa = 0
kekka = "" 
num = []
hantei = "OK"
INF = input().split()
gyosu = int(INF[1])
keta = int(INF[0])
out = []
for l in range(keta):
  out.append(0)


for i in range(gyosu):
  num.append([int(j) for j in input().split()])

if gyosu > 0 :
  check = int(num[0][0])
  check2 = int(num[0][1])
  
  for j in range(gyosu-1):
    for k in range(gyosu-1):
      if num[j][0] == num[k + 1][0]:
        if num[j][1] != num[k + 1][1]:
          hantei = "NG"
    
    if int(num[j][0]) < check: # 入力値にある最大桁数を計算
      check = int(num[j][0])
      check2 = int(num[j][1])
  if check2 == 0:
    if check == 1 and keta == 3:
      hantei = "NG"
    if check == 2:
      hantei = "tokubetu2"
    if check == 3:
      hantei = "tokubetu"

if hantei == "NG":
  print("-1")
else:
  for m in range(gyosu):
    
    out[(num[m][0] - 1)] = num[m][1]
  for n in range(keta):
    kekka = kekka + str(out[n])

  for p  in kekka:
      if p == "0":
        kensa = kensa + 1
      else:
        break
  kekka2 = kekka
  for q in range(kensa):
    if keta != 1:
      kekka = kekka.lstrip("0")
if hantei == "OK":
  if gyosu == 0:
    if keta == 1:
      print("0")
    elif keta == 2:
      print("10")
    else:
      print("100")
  else:
    if keta == 2:
      if kensa == 1:
        kekka = "1" + kekka
    if keta == 3:
      if kensa == 1:
        kekka = "1" + kekka
      if kensa == 2:
        kekka = "10" + kekka
    print(kekka)

if hantei == "tokubetu":
  print("0")


if hantei == "tokubetu2":
  #kekka2 = kekka2.lstrip("0")
  kekka2 = kekka2[1:]
  kekka2 = "1" + kekka2
  print(kekka2)

# Optimized solution
n,m = list(map(int,input().split()))
ans_list = ["x"]*n
for i in range(m):
    a,b = list(map(int,input().split()))
    b = str(b)
    #print(ans_list)
    if ans_list[a-1] != b and ans_list[a-1] != "x":
        print((-1))
        exit()
    else:
        ans_list[a-1] = b
if ans_list[0] == "0" and n != 1:
    print((-1))
    exit()
#print(ans_list)
if ans_list[0] == "x" and n != 1:
    ans_list[0] = "1"

for i in range(n):
    if ans_list[i] == "x":
        ans_list[i] = "0"
ans = ""
flag = "off"
for i in ans_list:
    if i != "0":
        flag = "on"
    if flag == "on":
        ans += i
if ans == "":
    ans = 0
print(ans)
# Original solution
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=list(map(int,input().split()))
S=[]
C=[]
for i in range(M):
  s,c=list(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))    

# Optimized solution
N,M=list(map(int,input().split()))
#SC=[s,c for input().split() in range(M)]
SC=[list(input().split()) for i in range(M)]
'''
SC=[]
for i in range(M):
  SC.append((input().split()))
'''
def check(x):
  x=str(x)
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[int(s)-1]!=c:
      return False
  return True
for i in range(1000):
  if check(i):
    print(i)
    exit()
print((-1))
# Original solution
N,M = list(map(int,input().split()))
from collections import defaultdict
sc = defaultdict(set)
for _ in range(M):
    s,c = list(map(int,input().split()))
    sc[s].add(c)


if N == 1:
    if len(sc[1]) > 1:
        print((-1))
    elif len(sc[1]) == 1:
        print((sc[1].pop()))
    else:
        print((0))
    exit()

ans = ""
for i in range(1,N+1):
    if len(sc[i]) > 1:
        print((-1))
        exit()

    if i == 1:
        if len(sc[i]) == 1:
            tmp = sc[i].pop()
            if tmp == 0:
                print((-1))
                exit()
            else:
                ans += str(tmp)
        else:
            ans += "1"
    else:
        if len(sc[i]) == 1:
            ans += str(sc[i].pop())
        else:
            ans += "0"

print(ans)

# Optimized solution
N,M = list(map(int, input().split()))
from collections import defaultdict
SC = defaultdict(set)
for _ in range(M):
    s,c = list(map(int, input().split()))
    SC[s].add(c)

if N == 1:
    if len(SC[1]) > 1:
        ans = -1
    elif len(SC[1]) == 1:
        ans = SC[1].pop()
    else:
        ans = 0
    print(ans)
    exit()

ans = ""
for i in range(1, N + 1):
    if len(SC[i]) > 1:
        ans = -1
        break

    if i == 1:
        if len(SC[i]) == 1:
            tmp = SC[i].pop()
            if tmp == 0:
                ans = -1
                break
            else:
                ans += str(tmp)
        else:
            ans += "1"
    else:
        if len(SC[i]) == 1:
            ans += str(SC[i].pop())
        else:
            ans += "0"

print(ans)
# Original solution
n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(m)]
 
for i in range(10**n):
  ans = str(i)
  if len(ans) != n:
    continue
  if all([ans[s-1] == str(c) for s, c in sc]):
    print(ans)
    break
else:
  print((-1))

# Optimized solution
n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(m)]
 
for i in range(10**n):
  ans = str(i)
  if len(ans) != n:
    continue
  if all([ans[s-1] == str(c) for s, c in sc]):
    print(ans)
    exit()

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


for i in range(1000):
    li = []
    j = str(i)
    for k in range(len(j)):
        li.append(int(j[k]))
    if len(li) != n:
        continue
    else:
        flag = True
        for s,c in sc:
            if li[s-1] != c:
                flag = False
        if flag:
            print(j)
            exit()

print((-1))


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

li = [-1] * n

for s,c in sc:
    if li[s-1] == -1 or li[s-1] == c:
        li[s-1] = c
    else:
        print((-1))
        exit()
    if n != 1 and s == 1 and c == 0:
        print((-1))
        exit()

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

ans = ''
for i in li:
    ans += str(i)

print((int(ans)))
# Original solution
ranges = [list(range(10)), list(range(10, 100)), list(range(100, 1000))]

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

ans = 0
found = False
for candidate in ranges[N - 1]:
    valid = True
    for i in range(M):
        if not (str(candidate)[s[i] - 1] == str(c[i])):
            valid = False
            break
    if valid:
        print(candidate)
        found = True
        break
if not found:
    print((-1))

# Optimized solution
N, M = list(map(int, input().split()))
ans = [-1 for i in range(N)]
valid = True
for i in range(M):
    s, c = list(map(int, input().split()))
    if ans[s - 1] < 0:
        ans[s - 1] = c
    elif ans[s - 1] != c:
        valid = False
     
if not valid:
    print((-1))
else:
    if N == 1:
        if ans[0] < 0:
            print((0))
        else:
            print((ans[0]))
    else:
        if ans[0] == 0:
            print((-1))
        else:
            if ans[0] < 0:
                ans[0] = 1
            for i in range(1, N):
                if ans[i] < 0:
                    ans[i] = 0
            print(("".join(map(str, ans))))
# Original solution
n,m = list(map(int,input().split()))
s,c = [0]*m,[0]*m
for i in range(m):
    s[i],c[i] = list(map(int,input().split()))
    s[i] -= 1
number = ['0']*n
for j in range(m):
    if number[s[j]] != '0' and number[s[j]] != str(c[j]):
        print('-1')
        quit()
    elif s[j] == 0 and c[j] == 0 and n != 1:
        print('-1')
        quit()
    else:
        number[s[j]] = str(c[j])
else:
    if number[0]  == '0' and  n != 1:
        number[0] = '1'

print((''.join(number)))

# Optimized solution
n,m = list(map(int,input().split()))
s,c = [0]*m,[0]*m
for i in range(m):
    s[i],c[i] = list(map(int,input().split()))
    s[i] -= 1
ans = ''
number = ['0']*n
for j in range(m):
    flag_1 = (number[s[j]] != '0' and number[s[j]] != str(c[j]))
    flag_2 = (s[j] == 0 and c[j] == 0 and n != 1)
    if flag_1 or flag_2:
        ans = '-1'
        break
    else:
        number[s[j]] = str(c[j])
else:
    if number[0]  == '0' and  n != 1:
        number[0] = '1'
    ans = ''.join(number)

print(ans)
# Original solution
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [line.rstrip() for line in sys.stdin.readlines()]

    ret = -1
    MIN = 0 if N == 1 else pow(10, N - 1)
    MAX = 10 if N == 1 else pow(10, N)
    for n in range(MIN, MAX):
        flg = True
        for line in lines:
            s, c = list(map(int, line.split()))
            t = str(n)

            if t[s - 1] != str(c):
                flg = False

        if flg:
            ret = n
            break

    print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

    ret = -1
    for n in range(0, pow(10, N)):
        if len(str(n)) != N:
            continue
        flg = True
        for s, c in lines:
            if str(n)[s - 1] != str(c):
                flg = False

        if flg:
            ret = n
            break

    print(ret)


if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(M)]
if N==1:
    for i in range(10):
        flg = 0
        for j in range(M):
            s,c = A[j]
            if str(i)[s-1]==str(c):
                continue
            else:
                flg = 1
                break
        if flg==0:
            print(i)
            break
    if flg==1:
        print((-1))
else:
    for i in range(10**(N-1),10**N):
        flg = 0
        for j in range(M):
            s,c = A[j]
            if str(i)[s-1]==str(c):
                continue
            else:
                flg = 1
                break
        if flg==0:
            print(i)
            break
    if flg==1:
        print((-1))

# Optimized solution
N,M = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(M)]
n = -1
for x in range(1000):
    x = str(x)
    if len(x)!=N:continue
    ind = 0
    for i in range(M):
        s,c = A[i]
        if x[int(s)-1]!=str(c):
            ind=1
            break
    if ind==0:
        n = x
        break
print(n)
# Original solution
n, m = list(map(int, input().split()))
num_list = ['X'] * n

def ans():
    if n == 1 and m == 0:
        return 0
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1

    for i in range(n):
        if num_list[i] == 'X':
            if i == 0:
                num_list[i] = '1'
            else:
                num_list[i] = '0'

    return ''.join(num_list)

print((ans()))


# Optimized solution
n, m = list(map(int, input().split()))
num_list = ['X'] * n

def ans():
    if n == 1 and m == 0:
        return 0
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1

    for i in range(n):
        if num_list[i] == 'X':
            num_list[i] = '1' if i == 0 else '0'

    return ''.join(num_list)

print((ans()))
# Original solution
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

for i in range(1000):
    flag = True
    for s in sc:
        num = str(i)
        if len(num) >= s[0] and str(s[1]) == num[s[0] - 1]:
            continue
        else:
            flag = False
            break
    if flag and len(str(i)) == n:
        print(i)
        exit()

print((-1))


# Optimized solution
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

for i in range(1000):
    flag = True
    num = str(i)
    for sc in v:
        if len(num) >= sc[0] and str(sc[1]) == num[sc[0] - 1]:
            continue
        else:
            flag = False
            break
    if flag and len(num) == n:
        print(i)
        exit()
print((-1))
# Original solution
import sys
input = sys.stdin.readline

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


for i in range(1000):
    S=str(i)

    if len(S)==N:
        for s,c in C:
            s-=1
            if S[s]==str(c):
                True
            else:
                break
        else:
            print(i)
            sys.exit()

print((-1))
                


# Optimized solution
import sys
input = sys.stdin.readline

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

score=[-1]*N

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

    if score[s]==-1 or score[s]==c:
        score[s]=c
    else:
        print((-1))
        sys.exit()
    
if N>1 and score[0]==0:
    print((-1))
    sys.exit()

for i in range(N):
    if score[i]==-1:
        score[i]=0

if score[0]==0 and N>1:
    score[0]=1

print(("".join(map(str,score))))
# Original solution
N,M = list(map(int,input().split()))

pattern = ["."] * N
for i in range(M):
  s,c = input().split()
  s = int(s)
  if pattern[s - 1] not in (".",c):
    print((-1))
    exit(0)
  pattern[s - 1] = c

import re

comp = re.compile("^" + "".join(pattern) + "$")

for i in range(1001):
  res = comp.match(str(i))
  if res:
    print(i)
    break
else:
  print((-1))


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

if N == 1:
  ans = ["0"]
  default = "0"
else:
  ans = ["1"] + ["0"] * (N - 1)
  default = "1" + "0" * (N - 1)

for i in range(M):
  s,c = input().split()
  s = int(s) - 1
  if N > 1 and s == 0 and c == "0":
    print((-1))
    exit(0)
  if ans[s] == default[s] or ans[s] == c:
    ans[s] = c
  else:
    print((-1))
    exit(0)
     
print(("".join(ans)))
# Original solution
N,M=list(map(int,input().split()))
SC=[input().split() for _ in range(M)]
ans=["0"]*N
for s,c in SC:
  if ans[int(s)-1]!="0" and ans[int(s)-1]!=c:
    print((-1))
    exit()
  if N>1 and s=="1" and c=="0":
    print((-1))
    exit()
  ans[int(s)-1]=c
if ans[0]=="0" and N>1:
  ans[0]="1"
print(("".join(ans)))

# Optimized solution
N,M=list(map(int,input().split()))
SC=[input().split() for _ in range(M)]
ans=["0"]*N
for s,c in SC:
  if ans[int(s)-1]!="0" and ans[int(s)-1]!=c:
    print((-1))
    exit()
  if N>1 and int(s)==1 and c=="0":
    print((-1))
    exit()
  ans[int(s)-1]=c
if N>1 and ans[0]=="0":
  ans[0]="1"
print(("".join(ans)))
# Original solution
n, m = list(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))
    


# Optimized solution
n, m = list(map(int, input().split()))
lst = [list(input().split()) for _ in range(m)]

ans = [''] * 3
for [s, c] in lst:
    s = int(s) - 1
    if ans[s] in ['', c]:
        ans[s] = c 
    else:
        print((-1))
        exit()


if n == 1:
    if m == 0:
        print((0))
        exit()
    else:
        ans = ans[0]
        print(ans)
        exit()

if n == 2 and m == 0:
    print((10))
    exit()

if n == 3 and m == 0:
    print((100))
    exit()

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

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

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

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

if n == 2:
    ans.pop()
ans = ''.join(ans)
print(ans)
# Original solution
n,m = list(map(int,input().split()))
req = [list(map(int,input().split())) for i in range(m)]

for i in range(10000):
  st = str(i)
  if len(st) != n:
    continue
  ok = True
  for s,c in req:
    if int(st[s-1]) != int(c):
      ok = False
  if ok:
    print(st)
    exit()
    
print((-1))

# Optimized solution
N,M = list(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))
# Original solution
import sys

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

if m == 0 and n == 1:
  print((0))
  sys.exit()
elif m == 0 and n != 1:
  print((10**n // 10))
  sys.exit()


for _ in range(m):
  sc.append(list(map(int,input().split())))

sc.sort()

if n == 1:
  tmp = 0
  for i in range(m):
    if sc[i][0] == 1 and sc[i][1] == 0:
      tmp += 1
    if tmp == m:
      print((0))
      sys.exit()

if sc[0][0] == 1 and sc[0][1] == 0:
  print('-1')
  sys.exit()

ans = [-1 for _ in range(n)]
for i in range(m):
  if ans[sc[i][0]-1] == -1:
    ans[sc[i][0]-1] = sc[i][1]
  else:
    if ans[sc[i][0]-1] != sc[i][1]:
      print('-1')
      sys.exit()

res = ''
if ans[0] == -1:
  ans[0] = 1
for i in range(n):
  if ans[i] == -1:
    ans[i] = 0
  res = res + str(ans[i])

print(res)


# Optimized solution
import sys

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

sc.sort()
ans = ['0' for _ in range(n)]
if n > 1:
	ans[0] = '1'
d = {}
for i in range(m):
	if sc[i] == [1,0]:
		if n > 1:
			print((-1))
			sys.exit()
	if sc[i][0] not in d:
		d[sc[i][0]] = sc[i][1]
	else:
		if d[sc[i][0]] != sc[i][1]:
			print((-1))
			sys.exit()

for i,v in list(d.items()):
	ans[i-1] = str(v)

print(("".join(ans)))
# Original solution
import math

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

candidate = []
for i in range(1000):
    if N == len(str(i)):
        candidate.append(i)

for _ in range(M):
    s, c = list(map(int, input().split()))
    tmp = []
    for n in candidate:
        if int(str(n)[s - 1]) == c:
            tmp.append(n)
    candidate = tmp

if candidate:
    print((candidate[0]))
else:
    print((-1))

# Optimized solution
n, m = list(map(int, input().split()))
nums = []
for i in range(1000):
    if len(str(i)) == n:
        nums.append(i)

for _ in range(m):
    s, c = list(map(int, input().split()))
    next_nums = []
    for a in nums:
        if int(str(a)[s - 1]) == c:
            next_nums.append(a)
    nums = next_nums

print((nums[0] if nums else -1))
# Original solution
import collections
N, M = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(M)]
t = collections.defaultdict(int)
flag = True
for s, c in sc:
    if s in t and t[s] != c:
        flag = False
        break
    else:
        t[s] = c

if flag:
    ans = []
    for i in range(1, N+1):
        if i in t:
            if i == 1 and t[i] == 0 and N > 1:
                print((-1))
                exit(0)
            else:
                ans.append(t[i])
        else:
            if i != 1:
                ans.append(0)
            else:
                if N == 1:
                    ans.append(0)
                else:
                    ans.append(1)

    print(("".join(map(str, ans))))
else:
    print((-1))


# Optimized solution
N,M=list(map(int,input().split()))
d = dict()
for i in range(M):
  a,b=list(map(int,input().split()))
  if a not in d:
    d[a]=b
  else:
    if d[a]!=b:
      print((-1))
      exit(0)
tmp=0
for i in range(10):
  if 3 in d and d[3] != i:
    continue
  for j in range(10):
    if 2 in d and d[2] != j:
      continue
    for k in range(10):
      if N!=1 and k ==0:
        continue
      if 1 in d and d[1]!= k:
        continue
      print(((str(k)+str(j)+str(i))[:N]))
      exit(0)
print((-1))
# Original solution
N,M=list(map(int,input().split()))
d = dict()
for i in range(M):
  a,b=list(map(int,input().split()))
  if a not in d:
    d[a]=b
  else:
    if d[a]!=b:
      print((-1))
      exit(0)
tmp=0
for i in range(10):
  if 3 in d and d[3] != i:
    continue
  for j in range(10):
    if 2 in d and d[2] != j:
      continue
    for k in range(10):
      if N!=1 and k ==0:
        continue
      if 1 in d and d[1]!= k:
        continue
      print(((str(k)+str(j)+str(i))[:N]))
      exit(0)
print((-1))

# Optimized solution
N, M = list(map(int, input().split()))
ans = [-1]*N

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

for i in range(N):
    if ans[i] == -1:
        if i == 0 and N != 1:
            ans[i] = 1
        else:
            ans[i] = 0

print(("".join(map(str, ans))))
# Original solution
n,m = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(10000):
    s = str(i)
    if len(s) != n:
        continue
    ok = True
    for a, b in sc:
        if s[a - 1] != str(b):
            ok = False
            break
    if ok:
        print(i)
        exit()

print((-1))


# Optimized solution
n,m = list(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))
# Original solution
n, m = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(m)]
count = 0
for i in range(1000):
    count = 0
    i = str(i)
    if len(i) == n:
        for s, c in x:
            if i[s-1] == str(c):
                count += 1
            else:
                break
        if count == m:
            print(i)
            exit()
print((-1))

# Optimized solution
n, m = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(m)]
for i in range(10**(n-1) if n>1 else 0, 10**n):
    i = str(i)
    for s, c in x:
        if i[s-1] != str(c):
            break
    else:
        print(i)
        exit()
print((-1))