import sys

n, m = map(int, input().split())
s = [0]*m
c = [0]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())
ans = [-1]*n
flag = [False]*n
for si, ci in zip(s, c):
    if flag[si-1]:
        if ans[si-1] != ci:
            print(-1)
            sys.exit()
    else:
        ans[si-1] = ci
        flag[si-1] = True
head = -1
for i in range(n):
    if ans[i] != -1:
        head = i
        break
if head == -1:
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    res = ans[head:n]
    if res[0] == 0 and len(res) != 1:
        print(-1)
        sys.exit()
    for r in res:
        if r == -1:
            print("0", end='')
        else:
            print(r, end='')
    print()