n,m = map(int,input().split())
ans = [0] * n
e = [False] * n
for _ in range(m):
    s,c = map(int, input().split())
    s = s - 1
    if e[s] and ans[s] != c:
        print(-1)
        exit()
    if s == 0 and c == 0:
        print(-1)
        exit()
    ans[s] = c
    e[s] = True


if ans[0] == 0:
    print(1, end='')
else:
    print(ans[0], end='')

for i in range(1,n):
    if not e[i]:
        print(0, end='')
    else:
        print(ans[i], end='')
print()