N, M = map(int, input().split())
digits = []
num = [0] * N
flag = 0

for i in range(M):
    digits.append(list(map(int, input().split())))

for k in range(M):
    if num[digits[k][0]-1] == 0:
        num[digits[k][0]-1] = digits[k][1]
    else:
        if num[digits[k][0]-1] != digits[k][1]:
            flag += 1
            print(-1)

if flag != 1:
    if num[0] == 0:
        num[0] = 1
    if N == len(num):
        num = [str(a) for a in num]
        ans = ''.join(num)
        print(ans)
    else:
        print(-1)
