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

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