N, M = map(int, input().split(" "))

digit = [[] for i in range(3)]
for i in range(M):
    si, ci = map(int, input().split(" "))
    if si > N:
        print(-1)
        exit()
    if not ci in digit[si-1]:
        digit[si-1].append(ci)

for i in range(N):
    if len(digit[i]) > 1:
        print(-1)
        exit()

ans = 0
coef = 10 ** (N-1)
for i in range(N):
    if len(digit[i]) > 0:
        ans += min(digit[i]) * coef
    coef //= 10

if ans < 100 and N == 3:
    ans += 100
if ans < 10 and N == 2:
    ans += 10

print(ans)