import numpy as np

NM = list(map(int,input().split()))

if NM[0] == 1:
    num = np.arange(0,10)
elif NM[0] == 2:
    num = np.arange(0,100)
else:
    num = np.arange(0,1000)

num.tolist
num = [str(i) for i in num]
#print(num)
s = [list(map(int,input().split())) for i in range(NM[1])]
#print(s)

for i in s:
    i2 = i[0]-1
    i3 = str(i[1])
    #print(i2)
    num = [j for j in num if j[i2] == i3]

num = [int(i) for i in num]
num = np.array(num)
if len(num>0):
    print(np.min(num))
else:
    print(-1)
