N, M = map(int, input().rstrip().split())
if N == 0:
    print(-1)
else:
    d = {}
    success_flg = True
    for _ in range(M):
        s, c = map(int, input().rstrip().split())
        if s == 0:
            success_flg = False
            break
        if s > N:
            success_flg = False
            break
        elif s in d.keys() and c != d[s]:
            success_flg = False
            break
        else:
            d[s] = c
    if success_flg:
        tmp_result = '0' * N
        success_flg2 = True
        for s, c in d.items():
            if s == 1 and c == 0:
                success_flg2 = False
                print(-1)
                break
            tmp_result = tmp_result[:s - 1] + str(c) + tmp_result[s:]
        if success_flg2:
            if tmp_result[0] == '0':
                tmp_result = str(1) + tmp_result[1:]
            print(int(tmp_result))
    else:
        print(-1)
