CodeEff/ECCO huggingface dataset:
# Original solution
N , M = list(map(int,input().split()))
L = []
for _ in range(M):
    m = tuple(map(int,input().split()))
    L.append(m)
if N == 1:
    for ans in range(0,10):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print((-1))
    exit()
else:
    for ans in range(10 ** (N - 1),10 ** N ):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print((-1))
    exit()



# Optimized solution
N, M = list(map(int,input().split()))
L = []
for _ in range(M):
    m = tuple(map(int,input().split()))
    L.append(m)

if(N == 1): lower = 0
else:       lower = 10 ** (N - 1)

for ans in range(lower, 10 ** N ):
    ans = str(ans) 
    for x in L:
        if ans[x[0] - 1] != str(x[1]):
            break
    else: #一度もbreakされてない == 矛盾なし
        print(ans)
        exit()
#ねえよ
print((-1))
# Original solution
import sys

input = sys.stdin.readline

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

if M == 0:
    ans = 0
    if N == 2:
        ans = 10
    if N == 3:
        ans = 100
    print(ans)
    exit()

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

sc.sort(key=lambda x:x[1])
sc.sort(key=lambda x:x[0])

if sc[-1][0] > N:
    print((-1))
    exit()

for i in range(M):
    if sc[i][0] not in list(dic.keys()):
        dic[sc[i][0]] = [sc[i][1]]
    elif sc[i][1] not in dic[sc[i][0]]:
        dic[sc[i][0]].append(sc[i][1])

for value in list(dic.values()):
    if len(value) > 1:
        print((-1))
        exit()

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

ans = ['a'] * N

for i in range(M):
    ans[sc[i][0]-1] = sc[i][1] 

if ans[0] == 'a':
    ans[0] = 1
for i in range(len(ans)):
    if ans[i] == 'a':
        ans[i] = 0

out = ""
for i in range(len(ans)):
    out += str(ans[i])

print((int(out)))

# Optimized solution
import sys

input = sys.stdin.readline

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

if M == 0:
    ans = 0
    if N == 2:
        ans = 10
    if N == 3:
        ans = 100
    print(ans)
    exit()

sc = []
dic = dict()
out = ""
for _ in range(M):
    sc.append(list(map(int, input().split())))

sc.sort(key=lambda x:x[0])

if sc[-1][0] > N:
    print((-1))
    exit()

for i in range(M):
    if sc[i][0] not in list(dic.keys()):
        dic[sc[i][0]] = sc[i][1]
    elif dic[sc[i][0]] != sc[i][1]:
        print((-1))
        exit()

if N > 1 and sc[0][0] == 1 and sc[0][1] == 0:
    print((-1))
    exit()

ans = ['a'] * N

for i in range(M):
    ans[sc[i][0]-1] = sc[i][1] 

if ans[0] == 'a':
    ans[0] = 1
for i in range(len(ans)):
    if ans[i] == 'a':
        ans[i] = 0
    out += str(ans[i])

print((int(out)))
# Original solution
#n = int(input())
#s = input()
#n, k= map(int,input().split())
#da = list(map(int,input().split()))

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

ans = -1
for i in range(10**(n)):
    now = str(i)
    ju = True
    for j in range(m):
        if len(now) < da[j][0]:
            ju = False
            break
        if now[da[j][0]-1] != str(da[j][1]):
            ju= False
    if ju and len(str(now)) == n:
        ans = i
        break

print(ans)

# Optimized solution
# n = int(input())
# s = input()
n, m = list(map(int,input().split()))
# da = list(map(int,input().split()))
# a = [int(input()) for i in range(n)]
da = [list(map(int,input().split())) for i in range(m)]

def ch(x):
    k = len(x)
    if n!=k: return False
    for i in range(m):
        if k < da[i][0]:
            return False
        if x[da[i][0]-1] != str(da[i][1]):
            return False
    return True

def solve():
    for i in range(10**n):
        if(ch(str(i))):
            print(i)
            return
    print((-1))
    return

solve()
# Original solution
from collections import defaultdict

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

d = defaultdict(list)
for s, c in SC:
    d[s].append(c)


if any(len(set(v)) > 1 for v in list(d.values())):
    print((-1))
elif d[1] == [0] and N > 1:
    print((-1))
elif N == 1 and M == 0:
    print((0))
else:
    ans = [0] * N
    ans[0] = 1
    for i in range(N):
        if d[i + 1]:
            ans[i] = d[i + 1].pop()
            
    print(("".join(list(map(str, ans)))))


# Optimized solution

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

cand = [-1] * N
flag = False
for s, c in X:
    s -= 1
    if cand[s] == -1:
        cand[s] = c
    elif cand[s] != c:
        flag = True

if flag or (N > 1 and cand[0] == 0):
    print((-1))
else:
    ans = 0
    for i in range(N):
        if cand[i] == -1:
            if i == 0 and N > 1:
                cand[i] = 1
            else:
                cand[i] = 0
        ans += cand[i] * 10 ** (N - i - 1)
    print(ans)
# Original solution
def main():
  n, m = input_list()
  sc = []
  
  d = {}
  mk = 0
  for i in range(m):
    s, c = input_list()
    if s in d and d[s] != c:
      print((-1))
      exit()
    d[s] = c
    mk = max(s, mk)
  for i in range(1000):
    si = str(i)
    if len(si) < n:
      continue
    check = True
    ls = len(si)
    for keta, c in list(d.items()):
      if si[keta-1] != str(c):
        check = False
    if check:
      print(i)
      exit()
  print((-1))
  
def input_list():
  return list(map(int, input().split()))

import math
import fractions
main()

# Optimized solution
def main():
  n,m = input_list()
  sc = {}
  for i in range(m):
    s, c = input_list()
    if s in sc and sc[s] != c:
      print((-1))
      exit()
    sc[s] = c
  for i in range(1000):
    si = str(i)
    if len(si) != n:
      continue
    ok = True
    for keta, num in list(sc.items()):
      index = keta-1
      if si[index] != str(num):
        ok = False
    if ok:
      print(si)
      exit()
  print((-1))
  

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

import math
import fractions
import itertools
main()
# Original solution
n,m=list(map(int,input().split()))
sc=[]
for i in range(m):
    sc.append(list(map(int,input().split())))
# print((sc))
if n==1:l=[i for i in range(0,10)]
if n==2:l=[i for i in range(10,100)]
if n==3:l=[i for i in range(100,1000)]

for ll in l:
    k=list(str(ll))
    if all([k[s-1]==str(c) for s,c in sc]):
        print((str(ll)))
        exit()
print((-1))
        

# Optimized solution
def ii():return int(eval(input()))
def mi():return list(map(int,input().split()))


n,m=mi()
sc=[]
for _ in range(m):
  sc+=tuple(mi()),


if n==3:
  l=list(range(100,1000))
if n==2:
  l=list(range(10,100))
if n==1:
  l=list(range(0,10))


for i in l:
  num=str(i)
  if all([num[s-1]==str(c) for s,c in sc]):
    print(num)
    exit()


print((-1))
# Original solution
n,m = list(map(int, input().split()))

t = [-1]*n
for _ in range(m):
  s,c = list(map(int, input().split()))
  s -= 1
  if t[s] != -1 and t[s] != c:
    print((-1))
    exit()
  t[s] = c
  
if n != 1:
  if t[0] == 0:
    print((-1))
    exit()
    
  if t[0] == -1:
    t[0] = 1
    
  for i in range(1, n):
    if t[i] == -1:
      t[i] = 0
else:
  if t[0] == -1:
    t[0] = 0
    
print((''.join(map(str, t))))

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

p = [-1]*n
for i in range(m):
  s,c = list(map(int, input().split()))
  s -= 1
  if p[s] == -1:
    p[s] = c
  if p[s] != c:
    print((-1))
    exit()

if n == 1:
  if p[0] == -1:
    print((0))
    exit()
else:
  if p[0] == -1:
    p[0] = 1
  for i in range(1, n):
    if p[i] == -1:
      p[i] = 0
      
ans = ''
for i in p:
  ans += str(i)
ans = int(ans)

if len(str(ans)) == n:
  print(ans)
else:
  print((-1))
# Original solution
n,m=list(map(int,input().split()))
sl=[];cl=[]
for i in range(m):
    s,c=list(map(int,input().split()))
    sl.append(s)
    cl.append(c)

isThere=False
#ans=10**n-1

for i in range(10**n):
    st=list(str(i))
    flag=True
    if len(st)==n:
        for j in range(m):
            if st[sl[j]-1]!=str(cl[j]):
                flag=False
                break
        if flag:
            isThere=True
            ans=i
    if isThere:
        break
if isThere:
    print(ans)
else:
    print((-1))


# Optimized solution
#k=int(input())
n,m=list(map(int,input().split()))
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

sl=[]
cl=[]

for i in range(m):
    s,c=list(map(int,input().split()))
    sl.append(s)
    cl.append(c)
flag=False
for i in range(1000):
    if len(str(i))==n:
        val=str(i)
        temp_flag=True
        for s,c in zip(sl,cl):
            if val[s-1]!=str(c):
                temp_flag=False
                break
        if temp_flag:
            flag=True
            break
if flag:
    print(i)
else:
    print((-1))
# Original solution
import sys

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

x=[-1]*N
valid=True
for _ in range(M):
    s,c=list(map(int,input().split()))
    if x[s-1]!=-1 and x[s-1]!=c:
        print((-1))
        sys.exit()
    x[s-1]=c

if N>1 and x[0]==0:
    print((-1))
else:
    ans=0
    for i in range(N):
        if x[i]==-1:
            if i>0 or N==1:
                x[i]=0
            else:
                x[i]=1
        ans=ans*10+x[i]
    print(ans)


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

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

if x[0]==-1:
    x[0]=0+(N>1)
for i in range(N):
    if x[i]==-1: x[i]=0

print((''.join(map(str,x))))
# Original solution
# -*- coding: utf-8 -*-


def main():
    n, m = list(map(int, input().split()))
    s = list()
    c = list()

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

        s.append(si)
        c.append(ci)

    for i in range(1000):
        digit = list(str(i))

        if len(digit) != n:
            continue

        ok = True

        for j in range(m):
            if int(digit[s[j]]) != c[j]:
                ok = False

        if ok:
            print(i)
            exit()

    print((-1))


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    n, m = list(map(int, input().split()))
    s = list()
    c = list()

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

        s.append(si)
        c.append(ci)

    # KeyInsight
    # 全探索
    # https://www.youtube.com/watch?v=TdR816rqc3s&feature=youtu.be
    # https://drken1215.hatenablog.com/entry/2020/03/02/015100
    for i in range(1000):
        digit = list(str(i))

        # 入力の桁よりも小さい
        if len(digit) != n:
            continue

        ok = True

        # 各桁で矛盾がないかチェック
        # 誤読: 同じ桁で違う数字が出てきたらNGなのに、最小の数字を選択すればいいと思っていた
        # 境界値: 先頭の桁が0がどうかの判定をifで処理したつもりになっていた
        for j in range(m):
            if int(digit[s[j]]) != c[j]:
                ok = False

        if ok:
            print(i)
            exit()

    print((-1))


if __name__ == '__main__':
    main()
# Original solution
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
ans = float('inf')
k = 0
if n == 2: k = 10
elif n == 3: k = 100
for i in reversed(list(range(k, 1000))):
    #print(f'i: {i}')
    flg = True
    for s, c in sc:
        #print(f'{s}桁目が{c}?', end=' ')
        if list(str(i))[s-1] == str(c): continue
        #print('No!')
        flg = False
    
    if flg:
        ans = min(ans, i)
        #print('ans: ', ans)
if ans == float('inf'): ans = -1
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
ans = float('inf')
k = 0
if n == 2: k = 10
elif n == 3: k = 100
for i in range(k, 1000):
    flg = True
    for s, c in sc:
        if list(str(i))[s-1] == str(c): continue
        flg = False
    if flg:
        ans = i
        break
if ans == float('inf'): ans = -1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(m)]

ans = -1
for i in range(1000):
        can = 1
        t = str(i)
        if len(t)!=n: continue
        for s,c in sc:
                if int(t[s-1])!=c: can = 0
        if can:
                ans = i
                break

if ans<0: print((-1))
else: print(ans)

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

for i in range(1000):
        x = str(i)
        if len(x)!=n: continue
        can = 1
        for s,c in sc:
                if int(x[s-1])!=c: can = 0
        if can:
                print(i)
                break
else: print((-1))
# Original solution
n,m=list(map(int,input().split()))
li=[]
if n==1:
    score="0"
else:
    score="1"+"0"*(n-1)
for i in range(m):
    s,c=list(map(int,input().split()))
    if n!=1 and s==1 and c==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)))

# Optimized solution
n,m=list(map(int,input().split()))
li=[]
if n==1:
    score="0"
else:
    score="1"+"0"*(n-1)
for i in range(m):
    s,c=list(map(int,input().split()))
    if n!=1 and (s,c)==(1,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)))
# Original solution
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

s = [sc[i][0] for i in range(len(sc))]
c = [sc[i][1] for i in range(len(sc))]

judge=False
for i in range(len(s)):
    for j in range(len(s)):
        if s[i]==s[j] and c[i] != c[j]:
            print((-1))
            judge=True
            break
        break




target = [0 for i in range(N)]

if N != 1 and target[0]==0:
    target[0]=1

for i in range(M):
    target[sc[i][0]-1] = sc[i][1]

if judge==False:
    res=0
    for i in range(N):
        res = res + target[i]*(10**(N-i-1))
    if len(str(res)) != N:
        print((-1))
    else:
        print(res)


# Optimized solution
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]
judge = False
target = [-1 for i in range(N)]
for i in range(M):
    if sc[i][1] + target[sc[i][0]-1] == sc[i][1]-1 or sc[i][1] + target[sc[i][0]-1] == 2*sc[i][1]:
        target[sc[i][0]-1] = sc[i][1]
    else:
        print((-1))
        judge = True
        break

if judge is False:
    for i in range(N):
        if len(target) == 1:
            if target[0] == -1:
                target[0] = 0
        else:
            if i == 0 and target[i] == -1:
                target[i] = 1
            elif target[i] == -1:
                target[i] = 0

    res = 0
    for i in range(N):
        res = res+target[i]*(10**(N-i-1))
    if len(str(res)) != N:
        print((-1))
    else:
        print(res)
# Original solution
N, M = list(map(int, input().split()))
scs = [tuple(map(int, input().split())) for _ in range(M)]

if N == 1:
    L, R = 0, 9
elif N == 2:
    L, R = 10, 99
else:
    L, R = 100, 999

for x in range(L, R+1):
    ss = list(map(int, str(x)))
#    print(x, ss)
    for s, c in scs:
        if ss[s-1] != c:
            break
    else:
        print(x)
        break
else:
    print((-1))


# Optimized solution
import sys

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

anss = [-1] * N
for s, c in scs:
    s -= 1
    if anss[s] != -1 and anss[s] != c:
        print((-1))
        sys.exit()
    if N >= 2 and s == 0 and c == 0:
        print((-1))
        sys.exit()
    anss[s] = c

for i in range(N):
    if anss[i] == -1:
        if N >= 2 and i == 0:
            anss[i] = 1
        else:
            anss[i] = 0

print((''.join(map(str, anss))))
# Original solution

def myAnswer(N:int,M:int,S:list,C:list)-> int:
   ans=-1
   for i in range(10**N):
      if(len(str(i)) == N):
          for s,c in zip(S,C):
              tmp=list(str(i))
              if(tmp[s-1] != str(c)):
                  break
          else:
              if(ans == -1):
                  ans=i
              else:
                ans=min(ans,i)
   return ans
def modelAnswer():
   return
def main():
   N,M = list(map(int,input().split()))
   S= []
   C = []
   for _ in range(M):
      s,c =list(map(int,input().split()))
      S.append(s)
      C.append(c)
   print((myAnswer(N,M,S[:],C[:])))

if __name__ == '__main__':
   main()




# Optimized solution

def solve(N,M,S,C) -> int:
    for n in range(10**N):
        length = len(str(n))
        if(length == N):
            n = str(n)
            for s,c in zip(S,C):
                if(int(n[s-1]) != c):
                    break
            else:
                return n
    return -1


def main():
    N,M = list(map(int,input().split()))
    S = []
    C = []
    for _ in range(M):
        s,c = list(map(int,input().split()))
        S.append(s)
        C.append(c)
    # solve()
    print((solve(N,M,S,C)))
if __name__ == "__main__":
    main()
# Original solution
def main():
    N, M = (int(i) for i in input().split())
    from collections import defaultdict
    dic = defaultdict(set)
    for i in range(M):
        s, c = (int(i) for i in input().split())
        dic[s].add(c)
    if 0 in dic[1] and N != 1:
        return print(-1)
    for i in range(1, N+1):
        if len(dic[i]) > 1:
            return print(-1)
        elif not(dic[i]):
            dic[i].add(0 if i != 1 or N == 1 else 1)
    # print(dic)
    s = ""
    for i in range(1, N+1):
        s = s + str(dic[i].pop())
    print(s)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (i for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    for t in range(1000):
        t = str(t)
        if len(t) != N:
            continue
        for k, v in dic.items():
            if t[int(k)-1] != v:
                break
        else:
            return print(t)
    print(-1)


if __name__ == '__main__':
    main()
# Original solution
def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (int(i) for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    # print(dic)
    for i in range(1000):
        s = str(i)
        if len(s) != N:
            continue
        for j in range(1, N+1):
            p = int(s[j-1])
            if (j in dic.keys()) and (dic[j] != p):
                break
        else:
            return print(i)
    print(-1)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (i for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    # print(dic)
    for i in range(1000):
        s = str(i)
        if len(s) != N:
            continue
        for k, v in dic.items():
            if s[int(k)-1] != v:
                break
        else:
            return print(i)
    print(-1)


if __name__ == '__main__':
    main()
# Original solution
import time
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def No():
    print((-1))
    exit()


N,M=input_int_list()
s_c_tuple_list=[input_int_list() for i in range(M)]
the_dict={}
for tup in s_c_tuple_list:
    s,c=tup
    if s==1 and c==0:
        if N==1:
            pass
        else:
            No()
    if s in the_dict:
        if the_dict[s]==c:
            pass
        else:
            No()
    else:
        the_dict[s]=c

if 1 not in the_dict:
    if N==1:
        the_dict[1]=0
    else:
        the_dict[1]=1
time.sleep(2)
the_num=int("".join([str(the_dict[i+1]) if i+1 in the_dict else str(0) for i in range(N)]))

print(the_num)


# Optimized solution
import time
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def No():
    print((-1))
    exit()


N,M=input_int_list()
s_c_tuple_list=[input_int_list() for i in range(M)]
the_dict={}
for tup in s_c_tuple_list:
    s,c=tup
    if s==1 and c==0:
        if N==1:
            pass
        else:
            No()
    if s in the_dict:
        if the_dict[s]==c:
            pass
        else:
            No()
    else:
        the_dict[s]=c

if 1 not in the_dict:
    if N==1:
        the_dict[1]=0
    else:
        the_dict[1]=1
the_num=int("".join([str(the_dict[i+1]) if i+1 in the_dict else str(0) for i in range(N)]))

print(the_num)
# Original solution
N, M = list(map(int, input().split()))
sc= [list(input().split()) for i in range(M)]
ans = -1
for i in range(10**N):
    if len(str(i)) != N:
        continue
    else:
        cnt = 0
        s = str(i)
        for j in range(M):
            if s[int(sc[j][0])-1] == sc[j][1]:
                cnt += 1
        if cnt == M:
            ans = i
            break
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
sc= [list(input().split()) for i in range(M)]
ans = -1
for i in range(10**N):
    if len(str(i)) != N:#N桁の数だけを考える
        continue
    else:
        cnt = 0
        s = str(i)
        for j in range(M):
            if s[int(sc[j][0])-1] == sc[j][1]:
                cnt += 1
        if cnt == M:#全ての条件を満たすものが解
            ans = i
            break
print(ans)
# Original solution
n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for j in range(m)]
for i in range(0 if n == 1 else 10**(n - 1), 10**n):
    if all(str(i)[s - 1] == str(c) for s, c in sc):
        print(i)
        break
else:
    print((-1))

# Optimized solution
n, m = list(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))
# Original solution
n, m = list(map(int, input().split()))

listans = ["0"] * n
ans = 0

for i in range(m):
    s, c = list(map(str, input().split()))
    if n > 1 and s == "1" and c == "0":
        ans = -1
    if listans[int(s)-1] != c:
        if listans[int(s)-1] == "0":
            listans[int(s)-1] = c
        else :
            ans = -1

if ans == 0:
    if n > 1 and listans[0] == "0":
        listans[0] = "1"
    ans = int("".join(listans))

print(ans)

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

listans = [0] * n
ans = 0

for i in range(m):
    s, c = list(map(int, input().split()))
    s -= 1
    if listans[s] == 0:
        listans[s] = c
    elif listans[s] != c:
        ans = -1
    if n > 1 and s == 0 and c == 0:
        ans = -1

if n > 1 and listans[0] == 0:
    listans[0] = 1

if ans == 0:
    ans = "".join([str(li) for li in listans])

print(ans)