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])
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)