n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(list(map(int,input().split())))
a=sorted(a,key=lambda x:x[0])
if n>=2 and a[0]==[1,0]:
    print(-1)
    exit()
for i in range(m-1):
    if a[i][0]==a[i+1][0] and a[i][1]!=a[i+1][1]:
        print(-1)
        exit()
for i in range(1000):
    i=str(i)
    f=1
    if a[-1][0]>len(i):
        continue
    for j in range(len(a)):
        if i[a[j][0]-1]!=str(a[j][1]):
            f=0
    if f:
        print(i)
        exit()
print(-1)