n, m = map(int, input().split())
sc = []
for i in range(m):
    s, c = map(int, input().split())
    sc.append((s, c))

ans = [-1] * n

if n == 1:
    for i in range(m):
        if sc[i][1] == 0:
            print(-1)
            exit()
        if ans[0] != sc[i][1] and ans[0] != -1:
            print(-1)
            exit()
        ans[0] = sc[i][1]
    print(sc[0][1])
    exit()

for i in range(m):
    if ans[sc[i][0]-1] != sc[i][1] and ans[sc[i][0]-1] != -1:
        print(-1)
        exit()
    if sc[i][0] == 1 and sc[i][1] == 0:
        print(-1)
        exit()
    ans[sc[i][0]-1] = sc[i][1]

if ans[0] == -1:
    ans[0] = 1

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0

for i in ans:
    print(i, end="")
print()
