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 flg ==0:
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
    if ans[0] == 0 or ans[0] == -1 and flg == 0 and sum(ans) > 0:
        ans[0] = 1
    print(*ans,sep="")
else:
    print(-1)