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

ans = [-1] * n

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

    else:
        ans[s] = c
        
if ans[0] == -1:
    ans[0] = 1

a = ""
for i in ans:
    a += str(i) if i != -1 else "0"
print(a)