N, M = map(int, input().split())

s_c_dict = {}

exit = 0
for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print("-1")
        exit= 1
        break
    if s in s_c_dict and s_c_dict[s] != c:
        print("-1")
        exit=1
        break

    s_c_dict[s] = c

ans = 0
if exit != 1:
    for i in range(1, N+1):
        if i in s_c_dict:
            ans += 10**(N-i) * s_c_dict[i]
        elif i == 1:
            ans += 10 ** (N-i) * 1
    print(ans)