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

if ans[0] == '*':
    ans[0] = '1'
if ans[0] == '0':
    print(-1)
else:
    ans = ''.join(ans)
    print(ans.replace('*', '0'))
