N,M = map(int,input().split())
Num = [-1 for i in range(N)]
for i in range(M):
    s,c = map(int,input().split())
    if Num[s-1] == -1:
        Num[s-1] = c
    elif Num[s-1] == c:
        pass
    else:
        print(-1)
        exit()
if N == 1:
    print(Num[0])
    exit()
if Num[0] == 0:
    print(-1)
else:
    if Num[0] == -1:
        Num[0] = 1
    for i in range(1,N):
        if Num[i]==-1:
            Num[i] = 0
    ans = ""
    for i in Num:
        ans += str(i)
    print(ans)