n, m = map(int, input().split())

check = [0 for i in range(n)]
ans = [0 for i in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if check[s - 1] and check[s - 1] != c:
        ans[0] = -1
        break
    check[s - 1] = c
    ans[s - 1] = c

if ans[0] == -1 or ans[0] == 0:
    print(-1)
else:
    a = ""
    for i in ans:
        print(i, end = "")