import sys
n,m = map(int,input().split())
lis = [-1] * n

for i in range(m):
    s,c = map(int,input().split())
    
    if lis[s-1] == -1 or lis[s-1] == c:
        lis[s-1] = c
    else:
        print(-1)
        sys.exit()
if n == 1:
    print(lis[0])
elif lis[0] == 0:
    print(-1)
elif lis[0] == -1:
    lis[0] = 1
    for i in lis:
        if i == -1:
            print(0, end="")
        else:
            print(i,end="")
else:
    for i in lis:
        if i == -1:
            print(0, end="")
        else:
            print(i,end="")