n, m = map(int, input().split())
if m == 0:
    if n == 1:
        print(0)
    if n == 2:
        print(10)
    if n == 3:
        print(100)
    exit()
d = {}
for _ in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    if s in d and d[s] != c:
        print(-1)
        exit()
    d[s] = c
ans = ''
for idx in range(1, n + 1):
    ans += str(d.get(idx, 0))
print(int(ans))
