n, m = map(int, input().split())

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()

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

isExist = True
ans = [99] * n

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

ans = [0 if i == 99 else i for i in ans]
if n != 1 and ans[0] == 0:
    ans[0] = 1
ans = ''.join(list(map(str, ans)))

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