from sys import exit
n, m = list(map(int, input().split()))
ary = []
result = 0
for i in range(0, m):
    ary.append(list(map(int, input().split())))
flg_1 = -1
flg_2 = -1
flg_3 = -1
for i in ary:
    keta = n - i[0] + 1
    if (keta == 1 and flg_1 == -1) or (keta == 2 and flg_2 == -1) or (keta == 3 and flg_3 == -1):
        # 桁セット
        result += (10 ** (keta-1)) * i[1]
        if keta == 1:
            flg_1 = i[1]
        elif keta == 2:
            flg_2 = i[1]
        elif keta == 3:
            flg_3 = i[1]
    else:
        if keta == 1:
            if i[1] != flg_1:
                print(-1)
                exit()
        elif keta == 2:
            if i[1] != flg_2:
                print(-1)
                exit()
        elif keta == 3:
            if i[1] != flg_3:
                print(-1)
                exit()

if result == 0:
    # resultが0の時は1桁目が0でn=1の時のみ
    for i in range(0, m):
        if ary[i][0] == 1 and ary[i][1] == 0 and n == 1:
            print(0)
            exit()
        else:
            print(-1)
            exit()
print(result)
