import sys

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

sc = list()
ss = list()
cc = list()
for ii in range(0,m):
    sc.append(input().split())
  
for ii in range(0,m):
  ss.append(sc[ii][0])
  cc.append(sc[ii][1])
  
if len(list(set(ss))) != len(list(set(cc))):
    print('-1')
    sys.exit()

if (n >= 2):
    for ii in range(0,m):
        if (sc[ii][0] == 1) and (sc[ii][1] == 0):
            print('-1')
            sys.exit()

if n == 1:
    ns = 0
    ne = 9
elif n == 2:
    ns = 10
    ne = 99
elif n == 3:
    ns = 100
    ne = 999

for ii in range(ns,ne+1):
    iis = str(ii)
    check = 0
    for line in sc:
        if iis[int(line[0])-1] == line[1]:
            check = check + 1

    if check == len(sc):
        print(ii)
        sys.exit()

print('-1')