n,m=map(int,input().split())

ans=[-1] * n

for i in range(m):
    s,c=map(int,input().split())
    s-=1

    if ans[s] != -1 and ans[s] != c:
        print(-1);exit()
    if n > 1 and s==0 and c== 0:
        print(-1);exit()

    ans[s]=c

for i in range(n):
    print(max(ans[i],0),end='')