n, m = map(int, input().split())
import sys
s = []
c = []
d = [-1] * n
for _ in range(m):
    i, j = map(int, input().split())
    if i == 1 and j == 0:
        print(-1)
        sys.exit()
    if d[i-1] == -1 or d[i-1] == j:
        d[i-1] = j
    else:
        print(-1)
        sys.exit()
    s.append(i)
    c.append(j)

if max(s) > n:
    print(-1)
    sys.exit()
else:
    for i, j in enumerate(d):
        if j == -1:
            if i == 0:
                continue
            else:
                d[i] = 0
print(*d, sep='')