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

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

for k in range(M):
    if constraints[k][0] == 1 and constraints[k][1] == 0:  # 最上位が0のケースは即アウト
        flag += 1
        print(-1)
        break
    if num[constraints[k][0] - 1] == 0:  # 位sが空っぽの場合、cを入れる
        num[constraints[k][0] - 1] = constraints[k][1]
    else:
        if num[constraints[k][0] - 1] != constraints[k][1]:  # 位sの条件について矛盾し、アウト
            flag += 1
            print(-1)

if flag != 1:  # 上で矛盾が生じなかった場合
    if num[0] == 0:
        num[0] = 1
    num = [str(a) for a in num]
    ans = ''.join(num)
    print(ans)
