n, m = map(int, input().split())
ans = [0] * n
e = []
for i in range(m):
    si, ci = map(int, input().split())
    e += [[si, ci]]
    for j in range(len(e)):
        if e[j][0] == si and e[j][1] != ci:
            print(-1)
            exit()
    if si == 1 and ci == 0:
        print(-1)
        exit()
    ans[si - 1] = ci
if len(ans) == 1 and ans[0] == 0:
    print(0)
    exit()
elif len(ans) != 1 and ans[0] == 0:
    ans[0] = 1
ans = map(str, ans)
print("".join(ans))