import sys
N,M = map(int,input().split())
result = [0]*N
for i in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0:
        print(-1)
        sys.exit()
    else:
        None
    if result[s-1] == 0:
        result[s-1] = c
    else:
        if result[s-1] == c:
            None
        else:
            print(-1)
            sys.exit()
if result[0] == 0 :
    result[0] = 1
ans = ""
for j in range(len(result)):
    ans += str(result[j])
print(ans)