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

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