N, M = map(int,input().split())
dic_number = {}
is_impossible = False
for _ in range(M):
    s,c = map(int,input().split())
    if s not in dic_number:
        dic_number[s] = c
    elif dic_number[s] == c:
        continue
    else:
        is_impossible = True


if is_impossible or (dic_number[1]==0):
    print(-1)
else:
    ans = 0
    for s in dic_number:
        ans += dic_number[s]*10**(N-s)

    if ans < 10**(N-1):
        ans += 10**(N-1)

    print(ans)