def main():
    # importも関数の中で実装する
    # ローカル変数化する
    # xxx
    N, N = map(int, input().split())
    SC = [list(map(int, input().split())) for _ in [0]*N ]
    SC.sort()

    num = (10 ** N) - 1
    keta = 1

    if SC[0][0] != 0:
        print('-1')
        exit()

    for S,C in SC:
        if S == 1 and C == 0:
            print('-1')
            exit()

        if S == keta:
            tmp = C * (10 ** (N - S))
            if tmp < num:
                num = tmp
        elif S > keta:
            keta = S
            tmp = C * (10 ** (N - S))
            num += tmp

    print(num)


main()