N,M = map(int,input().split())

sc = [list(map(int,input().split())) for _ in range(M)]
sc.sort()

ans = [-1]*N
ok = True
for i in range(M):
    if ans[sc[i][0]-1]==-1:
        ans[sc[i][0]-1] = sc[i][1]
    elif ans[sc[i][0]-1]!=sc[i][1]:
        ok = False
if ans[0]==0:
    ok = False
if ok:
    if ans[0]==-1:
        ans[0] = 1
    for i in range(N):
        if ans[i]==-1:
            ans[i] = 0
    ans = ''.join([str(a) for a in ans])
    print(ans)
else:
    print(-1)