l = input().split()
n, m = int(l[0]), int(l[1])
ans = ''
for _ in range(n):
    ans += 'x'
for _ in range(m):
    l = input().split()
    x, y = int(l[0]) - 1, l[1]
    try:
        if n >= x + 1 and ans[x] == 'x' or ans[x] == y:
            if x == 2:
                ans = ans[:2] + y
            elif x == 1:
                ans = ans[0] + y + ans[2]
            else:
                ans = y + ans[1:]
        else:
            ans = '-1'
            break
        if n >= 2 and ans[0] == '0' or ans[1] == '0':
            ans = '-1'
            break
    except:
        ans = '-1'
        break
ans = ans.replace('x', '0')
ans = int(ans)
if len(str(ans)) != n:
    ans = -1
print(ans)