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

isExist = True
ans = [99] * n

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()
else:
    for i in range(m):
        if ans[s[i] - 1] != 99 and ans[s[i] - 1] != c[i]:
            isExist = False
            break
        else:
            ans[s[i] - 1] = c[i]

ans = [0 if i == 99 else i for i in ans]

if sum(ans) == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()
else:
    ans = ''.join(list(map(str, ans)))

print(int(ans)) if isExist else print(-1)
