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

SClis = [] 
for _ in range(M):
    a, b = map(int, input().split())
    SClis.append([a,b])

ans = [-1]*N


for singlelis in SClis:
    digits = singlelis[0]-1
    number = singlelis[1]

    if ans[digits] == -1 or ans[digits] == number:
        ans[digits] = number
    else:
        print(-1)
        sys.exit()

if ans[0] == 0:
    print(-1)
    sys.exit()


kotae = ""
for i in range(N):
    i_str = str(ans[i])

    if i == 0 and i_str == "-1":
        kotae = kotae + "1"
        

    if i_str == "-1" and i != 0:
        kotae = kotae + "0"
    elif i_str != "-1" and i != 0:
        kotae = kotae + i_str

print(int(kotae))
     

