N, M = [int(x) for x in input().split(" ")]
digits = [-1] * N
flag = False
for i in range(M):
    s, c = [int(x) for x in input().split(" ")]
    if (digits[s-1] == -1 or digits[s-1] == c):
        digits[s-1] = c
    else:
        flag = True
        break
if (flag):
    print(-1)
elif (N != 1 and (digits[0] == 0 or digits[0] == -1)):
    print(-1)
else:
    for i in range(N):
        if (digits[i] != -1):
            print(digits[i], end="")
        else:
            print(0, end = "")
    print()