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

flg = 0
ans = [-1] * N
for c in s:
    if ans[c[0]-1] == -1:
      ans[c[0]-1] = c[1]
    if (ans[c[0]-1] != -1 and ans[c[0]-1] != c[1]):
      flg = -1

if ans[0] ==0 and sum(ans) <= 0:
    flg = -1

if flg ==0:
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == 0 and sum(ans) > 0:
        if ans[1]==0:
            ans[1] = 1
        else:
            ans[0] = 1
    if sum(ans)==0:
        print(0)
    else:
        if ans[0]==0:
            print(*ans[1:],sep="")
        else:
            print(*ans,sep="")
else:
    print(-1)