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

ans = [0] * N
ans[0] = 1
flag = [True] * N


for i in range(M):

    s,c = map(int,input().split())
    s -= 1

    if flag[s]:
        ans[s] = c
        flag[s] = False

    elif ans[s] != c:
        print (-1)
        sys.exit()

if ans[0] == 0:
    print (-1)
    sys.exit()
print ("".join(map(str,ans)))
