import sys

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

if N == 1:
    print(0)
    sys.exit()

A = [-1]*N
for i in range(M):
    s,c = map(int, input().split())
    if A[s-1] == -1:
        A[s-1] = c
    elif A[s-1] != c:
        print('-1')
        sys.exit()

if A[0] == -1:
    A[0] = 1

ans = ""
for a in A:
    if a == -1:
        ans += "0"
    else:
        ans += str(a)

ng = ""
for _ in range(N):
    ng += "0"

if ng == ans:
    print('-1')
else:
    print(ans)