N, M = map(int, input().rstrip().split())
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] + str(c) + tmp_result[s + 1:]
    if success_flg2:
        if tmp_result[0] == '0':
            tmp_result = str(1) + tmp_result[1:]
        print(int(tmp_result))
else:
    print(-1)
