n,m = map(int,input().split())
# maxn = 10**n
a=[0 for i in range(m)]
b=[0 for i in range(m)]
for i in range(m):
    a[i],b[i] = map(int,input().split())

if n==1:
    minn =0
    maxn = 0
else:
    minn = 10**(n-1)
    maxn = 10**n

for i in range(maxn//10, maxn):
    tmp = str(i)
    ok = True
    for aa, bb in zip(a,b):
        if int(tmp[aa-1]) == bb:
            pass
        else:
            ok = False
            break
    if ok:
        print(i)
        break
else:
    print(-1)
