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

l = [0 for _ in range(N)]
bin_l = [False for _ in range(N)]

flg = True
for _ in range(M):
    i, n = list(map(int, input().split()))
    if bin_l[i-1] and (l[i-1] != n):
        flg = False
        break
    if sum(l[:i-1]) == 0 and n == 0:
        flg = False
        break
    l[i-1] = n
    bin_l[i-1] = True

if not flg:
    print(-1)
else:
    res = 0
    l.reverse()
    for i in range(N):
        res += l[i] * 10**(i)
    print(res)