import sys
input = sys.stdin.readline

N, M = [int(x) for x in input().split()]
sc = {}
sc_l = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    sc_l.append(tmp)
    sc[tmp[0]] = tmp[1]

if M == 0:
    print(-1)
    sys.exit()

for i in range(M):
    for j in range(i + 1, M):
        if 0 <= i < M and 0 <= j < M:
            if sc_l[i][0] == sc_l[j][0] and sc_l[i][1] != sc_l[j][1]:
                print(-1)
                sys.exit()

if 1 in sc.keys():
    if sc[1] == 0:
        print(-1)
        sys.exit()

ans = ["0"] * N

for i in sc.keys():
    ans[i - 1] = str(sc[i])

print("".join(ans))


