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

ans = ["-1"] * n
check = True

for i in range(m):
    if ans[s[i] - 1] == str(c[i]) or ans[s[i] - 1] == "-1":
        ans[s[i] - 1] = str(c[i])
    else:
        check = False
if n != 1 and ans[0] == "0":
    check = False
if ans.count("-1") == n:
    print(0)
else:
    for i in range(n):
        if ans[i] == "-1":
            if i == 0:
                ans[i] = "1"
            else:
                ans[i] = "0"

    if check:
        print(''.join(ans))
    else:
        print(-1)
