N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
if N == 1:
    print(0)
    exit()
ans = [-1 for _ in range(N)]
for s, c in sc:
    if ans[s-1] == -1:
        ans[s-1] = c
    if ans[s-1] != c:
        print(-1)
        exit()

if ans[0] == 0:
    print(-1)
    exit()
if ans[0] == -1:
    ans[0] = 1
res = str(ans[0])
for i in range(1, N):
    if ans[i] == -1:
        res += "0"
    else:
        res += str(ans[i])
print(res)