import sys
N,m=map(int,input().split())
ans=dict()

for _ in range(m):
    s,c=map(int,input().split())
    if not s in ans.keys():
        ans[s]=c
    else:
        if ans[s] != c:
            print(-1)
            sys.exit()

if N==1:
    rg=range(1,10)
elif N == 2:
    rg=range(10,100)
elif N == 3:
    rg=range(100,1000)
    
for n in rg:
    n=str(n)
    f=True
    for k in ans.keys():
        f = f & (int(n[k-1]) == ans[k])

    if f:
        print(n)
        sys.exit()
else:
    print(-1)