N,M = map(int,input().split())
S = [list(map(int,input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
check = [0 for _ in range(N)]
e = 0
for i in range(M):
    s = S[i][0]
    c = S[i][1]
    if check[s-1] == 0:
        check[s-1] = 1
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            e = 1
            break
if e == 1:
    print(-1)
else:
    if ans[0] == 0:
        if N == 1:
            print(0)
        else:
            ans[0] = 1
    else:
        d = 0
        for i in range(N):
            d += ans[i] * (10 ** (N-1-i))
        print(d)