n,m,*a=map(int,open(0).read().split())
for i in range(1001):
    if len(str(i))==n:
        if sum(str(i)[s-1]==str(c)for s,c in zip(a[::2],a[1::2]))==m:
            print(i)
            exit()
print(-1)