import sys
n,m = map(int,input().split())
ans = [-1 for i in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    s-=1
    if ans[s] == -1:
        ans[s] = c
    else:
        if c == ans[s]:
            continue
        else:
            print(-1)
            sys.exit()
    if n != 1:
        if ans[s] == 0:
            print(-1)
            sys.exit()
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
fans = ""
for i in range(n):
    fans += ans[i]
print(fans)
