N, M = [int(x) for x in input().split()]
s, c = [], []
ans_array = [None for _ in range(N)]

for i in range(M):
    s_i, c_i = [int(x) for x in input().split()]
    s.append(s_i)
    c.append(c_i)

for i in range(M):
    if ans_array[s[i] - 1] is None:
        ans_array[s[i] - 1] = c[i]
    else:
        if ans_array[s[i] - 1] != c[i]:
            print(-1)
            exit()

if ans_array[0] is not None:
    ans_array = [0 if num is None else num for num in ans_array]
else:
    print(-1)
    exit()

ans = int("".join([str(num) for num in ans_array]))
print(ans)