n, m = map(int, input().split())
ans = [0]*n
for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == 0:
        ans[s-1] = c
    else:
        print(-1)
        exit()

ans = [str(a) for a in ans]
ans = str(int(''.join(ans)))
if len(ans) != n:
    print(-1)
else:
    print(ans)