
result = None
N, M = [int(i) for i in input().split()]

a = [None for i in range(N)]

for i in range(M):
    s, c = [int(i) for i in input().split()]
    s = s - 1

    if a[s] is not None and c != a[s]:
        result = False
    a[s] = c

if a[0] is None:
    a[0] = 1

a.reverse()

if result is None:
    result = 0
    for i, num in enumerate(a):
        if num is None:
            num = 0
        result += num * 10**i

if result is False:
    result = -1


print(result)