import sys

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

ans = []
for _ in range(n):
    ans.append('a')

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == 'a' or ans[s-1] == str(c):
        ans[s-1] = str(c)
    else:
        print(-1)
        sys.exit()

if ans[0] == '0':
    print(-1)
    sys.exit()

ans = ''.join(ans).replace('a', '0')

if ans[0] == '0':
    ans = ans.replace('0', '1', 1)

print(int(ans))
