import sys
n, m = map(int, input().split())
ans = ['*'] * n

for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    c = str(c)
    if s == 0 and c == '0':
        print('-1')
        sys.exit()
    elif ans[s] == '*':
        ans[s] = c
    elif ans[s] != c:
        print('-1')
        sys.exit()

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

if ans[0] == '0' and len(ans) > 1:
    ans = '1' + ans[1:]

print(ans)
