import sys
N,M = map(int,input().split())
result = [0]*N
A = []
if N == 1:
    result = 10
    for i in range(M):
        s, c = map(int, input().split())
        if result > 9:
            result = c
        else:
            if result != c:
                print(-1)
                sys.exit()
    print(result)
else:
    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 c == 0:
            A.append(s)
    if result[0] == 0:
        result[0] = 1

    for k in range(len(A)):
        if result[A[k] - 1] != 0:
            print(-1)
            sys.exit()

    ans = ""
    for j in range(len(result)):
        ans += str(result[j])

    print(ans)

