import sys
N,M = map(int,input().split())
d = [-1 for _ in range(N)]
for _ in range(M):
    s,c = map(int,input().split())
    if d[s-1] == -1:
        d[s-1] = c
    else:
        if d[s-1] != c:
            print("-1")
            sys.exit()
if N==1:
    print("".join(map(str,d)))
else:
    if d[0]==0:
        print(-1)
        sys.exit()
    else:
        ans = ""
        for i in d:
            if i == -1:
                ans += "0"
            else:
                ans += str(i)
        print(ans)